Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions services/common/src/ticket_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ pub struct Notice {
/// When it was posted (RFC 3339).
#[serde(default)]
pub at: String,
/// The GitHub issue comment's id, so a later update edits it instead of
/// posting another; 0 when unknown (a Jira comment, an older record).
#[serde(default)]
pub comment_id: u64,
}

/// The decisions on a record, oldest first; empty when unreadable.
Expand Down Expand Up @@ -186,8 +190,68 @@ pub fn posted_before<'a>(
.find(|n| n.text_hash == text_hash || (!decided && n.key == key && !key.is_empty()))
}

/// A notice's text as compared with earlier ones: whitespace collapsed,
/// markdown emphasis dropped, and dates, times and run links taken out, so
/// the same note posted by two runs minutes apart reads the same.
pub fn notice_text(text: &str) -> String {
let mut out: Vec<String> = Vec::new();
for word in text.split_whitespace() {
let w = word.replace("**", "").replace('`', "");
let bare = w.trim_matches(|c: char| !c.is_ascii_alphanumeric());
let stamp = bare.chars().filter(|c| c.is_ascii_digit()).count() >= 2
&& bare.contains([':', '-', '/'])
&& bare.chars().all(|c| {
c.is_ascii_digit() || matches!(c, '-' | ':' | '.' | 'T' | 'Z' | '+' | '/')
});
let run_link = w.contains("/runs/") || w.contains("run_id=") || w.contains("?id=");
if stamp || run_link || w.is_empty() {
continue;
}
out.push(w.to_lowercase());
}
out.join(" ")
}

/// The hash a notice is recorded under: its key and its compared text.
pub fn notice_hash(key: &str, text: &str) -> String {
crate::sha256_hex(&[key, &notice_text(text)])
}

/// What to do with a notice about to be posted on the ticket.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NoticeAction<'a> {
/// The same text is already on the ticket: post nothing.
Skip(&'a Notice),
/// An earlier notice about the same thing says something else and can
/// be edited (a GitHub comment): edit it in place.
Edit(&'a Notice),
/// Nothing like it was posted, or the earlier one can't be edited.
Post,
}

/// One comment per thing on a ticket: a notice whose text was posted before
/// (in any run) is not posted again; one whose key was posted with other
/// text edits the earlier comment where the platform allows.
pub fn notice_action<'a>(notices: &'a [Notice], key: &str, text_hash: &str) -> NoticeAction<'a> {
if let Some(n) = notices.iter().rev().find(|n| n.text_hash == text_hash) {
return NoticeAction::Skip(n);
}
match notices
.iter()
.rev()
.find(|n| !key.is_empty() && n.key == key && n.comment_id > 0)
{
Some(n) => NoticeAction::Edit(n),
None => NoticeAction::Post,
}
}

/// `notices` with `new` added, the oldest dropped past [`MAX_NOTICES`].
pub fn with_notice(mut notices: Vec<Notice>, new: Notice) -> Vec<Notice> {
// An edited comment keeps one record: the newest text for its key.
if new.comment_id > 0 {
notices.retain(|n| !(n.key == new.key && n.comment_id == new.comment_id));
}
notices.push(new);
if notices.len() > MAX_NOTICES {
let drop = notices.len() - MAX_NOTICES;
Expand Down Expand Up @@ -295,6 +359,7 @@ mod tests {
text_hash: "h1".into(),
url: "https://example.com/c/1".into(),
at: "2026-10-27T10:00:00Z".into(),
comment_id: 0,
};
let all = with_notice(Vec::new(), n);
// Same text: never again.
Expand All @@ -316,6 +381,60 @@ mod tests {
assert_eq!(many[0].key, "k10");
}

#[test]
fn the_same_note_from_two_runs_minutes_apart_is_posted_once() {
let first = "**Also needed outside the code**\n\nAdd the block on staging.\n\nChecked 2026-10-27T10:00:00Z, see https://app.example.com/runs/detail?id=r1";
let second = "**Also needed outside the code**\n\nAdd the block on staging.\n\n\nChecked 2026-10-27T10:07:12Z, see https://app.example.com/runs/detail?id=r2";
assert_eq!(notice_text(first), notice_text(second));
let h = notice_hash("also_outside", first);
assert_eq!(h, notice_hash("also_outside", second));
// A number that is content (a PR, a count) still counts.
assert_ne!(notice_text("see PR #12"), notice_text("see PR #13"));
let posted = with_notice(
Vec::new(),
Notice {
key: "also_outside".into(),
text_hash: h.clone(),
comment_id: 42,
..Default::default()
},
);
assert!(matches!(
notice_action(&posted, "also_outside", &h),
NoticeAction::Skip(_)
));
// New text about the same thing: the earlier comment is edited.
let other = notice_hash("also_outside", "Replace the block instead.");
match notice_action(&posted, "also_outside", &other) {
NoticeAction::Edit(n) => assert_eq!(n.comment_id, 42),
a => panic!("expected an edit, got {a:?}"),
}
// A Jira comment (no id) with new text is posted.
let jira = with_notice(
Vec::new(),
Notice {
key: "also_outside".into(),
text_hash: h,
..Default::default()
},
);
assert_eq!(
notice_action(&jira, "also_outside", &other),
NoticeAction::Post
);
// The edit keeps one record for the comment.
let edited = with_notice(
posted,
Notice {
key: "also_outside".into(),
text_hash: other,
comment_id: 42,
..Default::default()
},
);
assert_eq!(edited.len(), 1);
}

#[test]
fn intents_read_loosely() {
assert_eq!(
Expand Down
22 changes: 22 additions & 0 deletions services/worker/src/clients/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2561,6 +2561,28 @@ impl GitHubClient {
Ok(())
}

/// Replaces the body of a review already posted (no new notification).
pub async fn update_pr_review(
&self,
owner: &str,
repo: &str,
pr_number: u64,
review_id: u64,
body: &str,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let url = format!("{API_BASE}/repos/{owner}/{repo}/pulls/{pr_number}/reviews/{review_id}");
let headers = self.auth_headers().await?;
let mut req = self
.http
.put(&url)
.json(&serde_json::json!({ "body": body }));
for (k, v) in headers {
req = req.header(k, v);
}
ok_or_body(req.send().await?).await?;
Ok(())
}

/// List tags on a repo (used to compute the next semver release tag).
pub async fn list_tags(
&self,
Expand Down
128 changes: 126 additions & 2 deletions services/worker/src/passes/feature/checklist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
//! - the checks of each test package outside the main workspace;
//! - the new spec run repeatedly (`--repeat-each=5`) against the preview;
//! - for UI work, a no-horizontal-scroll check at a narrow and a wide
//! viewport in the spec ([`responsive_checked`]).
//! viewport in the spec ([`responsive_checked`]);
//! - a new or changed end-to-end test never skips itself when the content
//! or data it needs is missing: it fails, naming what is missing
//! ([`data_skips`]). Only a skip for a stated browser or platform
//! condition is allowed; a test that skips on missing content can never
//! fail.
//!
//! The counts and results go in the pull request; an item that fails keeps it
//! a draft.
Expand Down Expand Up @@ -575,6 +580,72 @@ pub fn root_steps(package_json: &str, tree: &[String]) -> Vec<Step> {
steps
}

/// Words that make a skip a browser or platform condition (allowed).
const PLATFORM_WORDS: &[&str] = &[
"browsername",
"isMobile",
"ismobile",
"process.platform",
"platform",
"webkit",
"firefox",
"chromium",
"safari",
"devicename",
"project.name",
"testinfo.project",
"viewport",
];

/// Skip calls in end-to-end test code.
const SKIP_CALLS: &[&str] = &[
"test.skip(",
"it.skip(",
"describe.skip(",
"test.describe.skip(",
"test.fixme(",
"testinfo.skip(",
"this.skip(",
"cy.skip(",
"pending(",
];

/// The skips a spec's diff adds that aren't for a browser or platform
/// condition, as "spec: line". Read from the added lines of the patch with
/// the lines just before each (an `if (!block) test.skip()` reads its
/// condition there).
pub fn data_skips(path: &str, patch: &str) -> Vec<String> {
let lines: Vec<&str> = patch.lines().filter(|l| !l.starts_with("@@")).collect();
let mut out = Vec::new();
for (i, l) in lines.iter().enumerate() {
if !(l.starts_with('+') && !l.starts_with("+++")) {
continue;
}
let code = l[1..].trim();
if code.starts_with("//") || code.starts_with('*') {
continue;
}
let low = code.to_ascii_lowercase().replace(' ', "");
if !SKIP_CALLS.iter().any(|c| low.contains(c)) {
continue;
}
let from = i.saturating_sub(3);
let context = lines[from..=i]
.iter()
.map(|x| x.get(1..).unwrap_or("").to_ascii_lowercase())
.collect::<Vec<_>>()
.join(" ");
if PLATFORM_WORDS
.iter()
.any(|w| context.contains(&w.to_ascii_lowercase()))
{
continue;
}
out.push(format!("{path}: `{}`", common::truncate_str(code, 120)));
}
out
}

/// What the static part of the checklist reads.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Facts {
Expand All @@ -595,6 +666,10 @@ pub struct Facts {
/// Their values no test names, as "name: value".
#[serde(default)]
pub options_untested: Vec<String>,
/// Skips the new or changed specs add for missing content or data, as
/// "spec: line" (see [`data_skips`]).
#[serde(default)]
pub data_skips: Vec<String>,
}

/// The items that read the diff alone.
Expand Down Expand Up @@ -667,6 +742,24 @@ pub fn static_items(f: &Facts) -> Vec<Item> {
));
}
}
if !f.specs.is_empty() {
if f.data_skips.is_empty() {
out.push(Item::new(
"end-to-end tests fail when their content is missing",
Status::Pass,
"no new or changed spec skips itself on missing content",
));
} else {
out.push(Item::new(
"end-to-end tests fail when their content is missing",
Status::Fail,
format!(
"skips on missing content, so the test can never fail: {}",
f.data_skips.join("; ")
),
));
}
}
if f.ui && !f.specs.is_empty() {
if f.responsive_specs.is_empty() {
out.push(Item::new(
Expand Down Expand Up @@ -705,7 +798,11 @@ pub fn feedback(items: &[Item]) -> String {
shown and the hidden case of an on/off field). A new \
end-to-end spec goes in every test map the repository keeps. For UI, the spec checks \
`document.documentElement.scrollWidth <= window.innerWidth` at a viewport {NARROW_MAX}px \
wide or less and one {WIDE_MIN}px wide or more.\n"
wide or less and one {WIDE_MIN}px wide or more. An end-to-end test never calls \
`test.skip` (or `fixme`, `it.skip`) when the content or data it needs is missing: rewrite \
it to fail with a message naming the missing content (for example \
`expect(block, 'staging page /x has no gallery block').toBeVisible()`); a skip is only \
for a stated browser or platform condition.\n"
));
s
}
Expand All @@ -714,6 +811,32 @@ pub fn feedback(items: &[Item]) -> String {
mod tests {
use super::*;

#[test]
fn a_spec_that_skips_on_missing_content_fails_the_checklist() {
let patch = "@@ -0,0 +1,12 @@\n+test('gallery renders', async ({ page }) => {\n+ await page.goto('/events')\n+ const block = page.locator('[data-block=gallery]')\n+ if ((await block.count()) === 0) {\n+ test.skip(true, 'no gallery block on staging')\n+ }\n+ // test.skip() in a comment is fine\n+ test.skip(browserName === 'webkit', 'webkit has no clipboard')\n+})\n";
let skips = data_skips("e2e/gallery.spec.ts", patch);
assert_eq!(skips.len(), 1, "{skips:?}");
assert!(skips[0].contains("no gallery block on staging"));
let f = Facts {
specs: vec!["e2e/gallery.spec.ts".into()],
data_skips: skips,
..Default::default()
};
let items = static_items(&f);
let item = items
.iter()
.find(|i| i.name.contains("content is missing"))
.unwrap();
assert_eq!(item.status, Status::Fail);
assert!(feedback(&items).contains("never calls `test.skip`"));
// A platform skip alone passes.
let ok = data_skips(
"e2e/a.spec.ts",
"@@\n+test.skip(process.platform === 'win32', 'paths')\n",
);
assert!(ok.is_empty());
}

#[test]
fn counts_the_cases_the_acceptance_criteria_list() {
let body = "Build the filter.\n\nAcceptance criteria:\n- Shows all events by default\n- Filters by venue\n1. Filters by date\n\n## Notes\n- not a case\n";
Expand Down Expand Up @@ -801,6 +924,7 @@ mod tests {
has_e2e: true,
options_found: 0,
options_untested: vec![],
data_skips: vec![],
};
let items = static_items(&f);
assert_eq!(failing(&items).len(), 3);
Expand Down
Loading
Loading