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
43 changes: 38 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
gcp_beginframe: ${{ steps.release.outputs.release_only == 'true' && 'false' || steps.filter.outputs.gcp_beginframe }}
studio: ${{ steps.release.outputs.release_only == 'true' && 'false' || steps.filter.outputs.studio }}
edit_accuracy: ${{ steps.release.outputs.release_only == 'true' && 'false' || steps.edit_accuracy_filter.outputs.edit_accuracy }}
sealed_preview: ${{ steps.release.outputs.release_only == 'true' && 'false' || steps.edit_accuracy_filter.outputs.sealed_preview }}
# The previews the edit accuracy bench measures: the merge queue's sealed one as well.
edit_accuracy_previews: ${{ github.event_name == 'merge_group' && '["unsealed","sealed"]' || '["unsealed"]' }}
steps:
Expand Down Expand Up @@ -223,12 +224,22 @@ jobs:
base: ${{ github.event_name == 'merge_group' && github.event.merge_group.base_sha || steps.base.outputs.sha }}
predicate-quantifier: some-with-excludes
filters: |
# What a sealed preview runs: a sealed drop fails the required bench gate only when one of these changed.
sealed_preview:
- "packages/core/src/runtime/**"
- "packages/core/src/inline-scripts/**"
- "packages/player/src/**"
- "packages/studio/src/**"
- "packages/studio-server/src/**"
- "packages/studio/tests/sealed-parity/**"
edit_accuracy:
- "packages/studio/src/**"
- "packages/studio/index.html"
- "packages/studio/vite.*.ts"
- "packages/studio/public/**"
- "packages/studio/tests/e2e/edit-accuracy/**"
- "packages/studio/tests/sealed-parity/manifest.json"
- "scripts/ci/sealed-parity.mjs"
- "packages/studio/tests/e2e/webmcp-host.mjs"
- "packages/studio-server/src/**"
- "packages/core/src/**"
Expand Down Expand Up @@ -1519,13 +1530,15 @@ jobs:
# Parity means the same cases pass in both modes, so the sealed runs are also judged against this head's
# unsealed verdicts (the full grid's baseline.json above). Only the parity row reads it; it gates nothing.
- name: Compare every sealed run with this head's unsealed runs
id: cross
if: contains(fromJSON(needs.changes.outputs.edit_accuracy_previews), 'sealed')
run: |
set +e
[ -f /tmp/edit-accuracy-gate/baseline.json ] || exit 0
mapfile -t RESULTS < <(find /tmp/edit-accuracy-sealed-shards -name results.json | sort)
node packages/studio/tests/e2e/edit-accuracy/ratchet.mjs gate --shards "$EDIT_ACCURACY_SHARDS" /tmp/edit-accuracy-gate/baseline.json \
/tmp/edit-accuracy-gate/baseline.json /tmp/edit-accuracy-gate-sealed/cross "${RESULTS[@]}"
echo "exit_code=$?" >> "$GITHUB_OUTPUT"
{ echo "## Sealed against this head's unsealed runs"; cat /tmp/edit-accuracy-gate-sealed/cross/comment.md; } >> "$GITHUB_STEP_SUMMARY" || true
- name: Post sticky comment
# Fork PRs get a read-only token; the gate below still fires. The merge queue has no PR to comment on.
Expand Down Expand Up @@ -1553,12 +1566,32 @@ jobs:
verdict=$(jq -r '.verdict // empty' /tmp/edit-accuracy-gate/gate.json 2>/dev/null)
echo "::error::${verdict:-The edit accuracy gate could not finish; see its log.}"
exit 1
- name: Fail if the sealed gate failed
if: steps.sealed.conclusion != 'skipped' && steps.sealed.outputs.exit_code != '0'
# A sealed drop fails this required check for a change to what a sealed preview runs, or while a default is
# sealed; any other change only gets a warning, so a sealed flake cannot drop it from the queue.
- name: Report a sealed drop, and fail on it when the change reaches a sealed preview
if: >-
(steps.sealed.conclusion != 'skipped' && steps.sealed.outputs.exit_code != '0') ||
(steps.cross.outputs.exit_code != '' && steps.cross.outputs.exit_code != '0')
shell: bash
env:
SEALED_PREVIEW_CHANGED: ${{ needs.changes.outputs.sealed_preview }}
SEALED_EXIT: ${{ steps.sealed.outputs.exit_code }}
run: |
verdict=$(jq -r '.verdict // empty' /tmp/edit-accuracy-gate-sealed/gate.json 2>/dev/null)
echo "::error::Sealed preview: ${verdict:-the sealed edit accuracy gate could not finish; see its log.}"
exit 1
verdict_of() { jq -r '.verdict // empty' "$1" 2>/dev/null || true; }
if [ "${SEALED_EXIT:-1}" != 0 ]; then
verdict=$(verdict_of /tmp/edit-accuracy-gate-sealed/gate.json)
else
verdict=$(verdict_of /tmp/edit-accuracy-gate-sealed/cross/gate.json)
verdict="${verdict:+${verdict} (against the unsealed runs on this head)}"
fi
message="Sealed preview: ${verdict:-the sealed edit accuracy gate could not finish; see its log.}"
probe=0
node scripts/ci/sealed-parity.mjs sealed-default || probe=$?
if [ "$SEALED_PREVIEW_CHANGED" = true ] || [ "$probe" != 3 ]; then
echo "::error::${message}"
exit 1
fi
echo "::warning::${message}"

smoke-global-install:
name: "Smoke: global install"
Expand Down
20 changes: 20 additions & 0 deletions scripts/check-edit-accuracy-filter.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,23 @@ test("the filter keeps the root manifest, lockfile and install script, and drops
])
assert.ok(!covered(path), `${path} should not run the bench`);
});

// A change the sealed preview runs makes a sealed drop fail the required gate; Studio bundles the player and the
// frame's inline script, so a player-only change counts, and an engine-only change only gets a warning.
test("the sealed preview filter counts player and runtime changes, not an engine-only one", () => {
const block = ci.match(/\n {12}sealed_preview:\n((?: {14}- .*\n)+)/);
assert.ok(block, "sealed_preview filter not found");
const sealed = matcher([...block[1].matchAll(/- "(.*)"/g)].map((m) => m[1]));
for (const path of [
"packages/player/src/hyperframes-player.ts",
"packages/core/src/inline-scripts/hyperframe.ts",
"packages/core/src/runtime/editing/dragChrome.ts",
"packages/studio/src/hooks/useDomEditNudge.ts",
])
assert.ok(sealed(path), `${path} should count as a sealed preview change`);
assert.ok(!sealed("packages/engine/src/services/videoFrameExtractor.ts"));
assert.ok(
!sealed("scripts/ci/sealed-parity.mjs"),
"a sealed preview never runs the parity script",
);
});
33 changes: 30 additions & 3 deletions scripts/ci/sealed-parity.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ export function sealedDefaults(read) {
});
}

/** Whether any default is sealed; one that can no longer be read counts as sealed, so a check fails closed. */
export function sealedDefault(defaults) {
const sealed = defaults.filter((d) => d.sealed !== false);
return {
sealed: sealed.length > 0,
lines: sealed.length
? sealed.map(
(d) =>
`${d.surface} ${d.sealed ? "is sealed by default" : `default unreadable in ${d.file}`}`,
)
: ["every default is unsealed"],
};
}

export function gate(parity, defaults) {
const unreadable = defaults.filter((d) => d.sealed === null);
if (unreadable.length > 0)
Expand All @@ -146,7 +160,7 @@ export function gate(parity, defaults) {
};
const sealed = defaults.filter((d) => d.sealed);
const failing = parity.filter((row) => row.verdict !== "parity");
// The merge queue's required edit accuracy gate refuses a sealed regression there.
// The merge queue's required edit accuracy gate refuses a sealed drop there while a default is sealed.
const refusing = failing.filter((row) => row.verdict !== "not measured");
const lines = [`${parity.length - failing.length} of ${parity.length} behaviours at parity`];
for (const row of failing) lines.push(` ${row.verdict}: ${row.id} (${row.behaviour})`);
Expand Down Expand Up @@ -221,14 +235,27 @@ function gateDefaults(_rows, [parityFile]) {
return report(result.lines, console.log, result.ok);
}

const COMMANDS = { run: runMode, compare: compareModes, gate: gateDefaults };
// Exits UNSEALED_DEFAULT only when every default was read as unsealed, so any other exit fails a check closed.
export const UNSEALED_DEFAULT = 3;
function isSealedDefault() {
const result = sealedDefault(sealedDefaults(readRepo));
for (const line of result.lines) console.log(line);
return result.sealed ? 0 : UNSEALED_DEFAULT;
}

const COMMANDS = {
run: runMode,
compare: compareModes,
gate: gateDefaults,
"sealed-default": isSealedDefault,
};

function main([command, ...args]) {
const { rows, problems } = readManifest(readRepo(MANIFEST));
if (command === "check") return check(rows, problems);
if (Object.hasOwn(COMMANDS, command)) return COMMANDS[command](rows, args);
console.error(
"usage: sealed-parity.mjs check | run <mode> <out> [--edit-accuracy <gate.json>] | compare <unsealed> <sealed> <out> | gate <parity>",
"usage: sealed-parity.mjs check | run <mode> <out> [--edit-accuracy <gate.json>] | compare <unsealed> <sealed> <out> | gate <parity> | sealed-default",
);
return 2;
}
Expand Down
20 changes: 20 additions & 0 deletions scripts/ci/sealed-parity.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { test } from "node:test";
import { fileURLToPath } from "node:url";
Expand All @@ -11,6 +12,8 @@ import {
filesByPackage,
gate,
readManifest,
sealedDefault,
UNSEALED_DEFAULT,
sealedDefaults,
unranTests,
verdicts,
Expand Down Expand Up @@ -119,6 +122,23 @@ test("the gate refuses a sealed Studio default while any behaviour is not at par
assert.equal(gate(compare(rows.slice(0, 1), passed, passed), defaults).ok, true);
});

test("a sealed or unreadable default counts as sealed for the required bench gate", () => {
assert.equal(sealedDefault(sealedDefaults(read)).sealed, false);
const sealed = sealedDefaults((path) => (path === STUDIO ? sealedStudio(path) : read(path)));
assert.equal(sealedDefault(sealed).sealed, true);
const unreadable = sealedDefaults((path) =>
path === STUDIO ? "export const X = 1;" : read(path),
);
assert.equal(sealedDefault(unreadable).sealed, true);
});

test("sealed-default exits 3 only when every default reads as unsealed, which today's do", () => {
const script = fileURLToPath(new URL("./sealed-parity.mjs", import.meta.url));
const result = spawnSync(process.execPath, [script, "sealed-default"], { encoding: "utf8" });
assert.equal(result.status, UNSEALED_DEFAULT);
assert.equal(UNSEALED_DEFAULT, 3);
});

test("a default the gate can no longer read fails it", () => {
const defaults = sealedDefaults((path) => (path === STUDIO ? "export const X = 1;" : read(path)));
assert.equal(gate([], defaults).ok, false);
Expand Down
73 changes: 72 additions & 1 deletion scripts/edit-accuracy-retry.test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { execFileSync, spawnSync } from "node:child_process";
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
Expand Down Expand Up @@ -184,3 +184,74 @@ test("only the merge queue measures a sealed preview; a pull request measures th
assert.deepEqual(JSON.parse(queue), ["unsealed", "sealed"]);
assert.deepEqual(JSON.parse(pr), ["unsealed"]);
});

// fails without the fix: a sealed case failing 2 of 3 runs failed the required gate and dropped an engine-only PR
// from the merge queue, and a missing sealed report ended the step at its jq read before any message.
test("a sealed drop fails the required gate only for a change a sealed preview runs, or a sealed default", () => {
const { run, env } = step(
"studio-edit-accuracy-gate",
"Report a sealed drop, and fail on it when the change reaches a sealed preview",
);
assert.equal(env.SEALED_PREVIEW_CHANGED, "${{ needs.changes.outputs.sealed_preview }}");
// No sealed gate.json under the tree: the step reads a missing report. A stand-in node answers sealed-default.
// The stand-in node is the default probe: 0 sealed, 3 unsealed, anything else a probe that failed.
const outcome = (changed, probe, exits = { SEALED_EXIT: "1" }, cross = null) =>
withTree((root) => {
if (cross) {
mkdirSync(join(root, "edit-accuracy-gate-sealed", "cross"), { recursive: true });
writeFileSync(
join(root, "edit-accuracy-gate-sealed", "cross", "gate.json"),
JSON.stringify(cross),
);
}
mkdirSync(join(root, "bin"));
writeFileSync(join(root, "bin", "node"), `#!/bin/sh\nexit ${probe}\n`, {
mode: 0o755,
});
const shell = run.replaceAll("/tmp/", `${root}/`);
const result = spawnSync("bash", ["-euo", "pipefail", "-c", shell], {
env: {
...process.env,
...exits,
PATH: `${root}/bin:${process.env.PATH}`,
SEALED_PREVIEW_CHANGED: changed,
},
encoding: "utf8",
});
return [result.status, result.stdout.trim()];
});
const missing = "Sealed preview: the sealed edit accuracy gate could not finish; see its log.";
assert.deepEqual(outcome("false", 3), [0, `::warning::${missing}`]);
assert.deepEqual(outcome("true", 3), [1, `::error::${missing}`]);
assert.deepEqual(outcome("false", 0), [1, `::error::${missing}`]);
assert.deepEqual(outcome("false", 1), [1, `::error::${missing}`]);
const fell = { verdict: "Edit accuracy fell against the base branch" };
const sameHead = `Sealed preview: ${fell.verdict} (against the unsealed runs on this head)`;
assert.deepEqual(outcome("true", 3, { SEALED_EXIT: "0" }, fell), [1, `::error::${sameHead}`]);
assert.deepEqual(outcome("false", 3, { SEALED_EXIT: "0" }, fell), [0, `::warning::${sameHead}`]);
assert.match(
step(
"studio-edit-accuracy-gate",
"Report a sealed drop, and fail on it when the change reaches a sealed preview",
).if,
/steps\.cross\.outputs\.exit_code != '0'/,
);
assert.match(
step("studio-edit-accuracy-gate", "Compare every sealed run with this head's unsealed runs")
.run,
/echo "exit_code=\$\?" >> "\$GITHUB_OUTPUT"/,
);
});

test("the sealed preview's paths are named once, in the change filter the bench gate reads", () => {
assert.match(
jobs.changes.outputs.sealed_preview,
/steps\.edit_accuracy_filter\.outputs\.sealed_preview/,
);
const { filters } = jobs.changes.steps.find((s) => s.id === "edit_accuracy_filter").with;
const sealed = parse(filters).sealed_preview;
assert.ok(
sealed.includes("packages/core/src/runtime/**") && sealed.includes("packages/studio/src/**"),
);
assert.ok(!sealed.some((glob) => glob.startsWith("packages/engine")));
});
Loading