@ai-ecoverse/slicc-shared-web 1.22.0 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -79,7 +79,7 @@ A workflow of its own (not this reusable one) gets the same line from the compos
79
79
 
80
80
  `.github/actions/cert-self-guard` is a shared composite action for PR certification lanes. It inspects the PR's diff against its base (both paths of a rename included) and rejects certification-path edits with `cert-review: needs coordinator review` unless `cert-review-approved` was applied after the current head **arrived at GitHub** by a user whose GitHub repository permission is **admin or maintain**. The arrival time is the earliest `created_at` from `commits/{sha}/check-suites`, or, if unavailable, the PR timeline's latest matching head-push event. If neither server-side source is available, approval is `INCOMPLETE`. The client-controlled committer date is retained only as information in the receipt; it never authorizes approval. Write permission is not enough. It reads the label application from the issue timeline and checks the labeler's current permission through the API, rather than trusting the event sender or the label's presence alone. Removing and reapplying the label replaces the approval event; an old application cannot qualify. Missing git history, API errors, stale heads, ambiguous group membership and truncated timeline evidence fail closed as `INCOMPLETE`.
81
81
 
82
- The guard's assumption is that **workers never apply or remove `cert-review-approved`; only a lane coordinator does, after reading the certification-path change**. The permission API cannot distinguish a coordinator from a worker: all agents act as `trieloff`, an admin. Coordinator-only labelling is therefore a **procedural assumption**, not something the permission check enforces. On `synchronize`, the guard itself removes that label automatically and blocks a touched PR until the coordinator approves its new head. A failed removal is red. This automated invalidation is not permission for workers to change the label manually. A re-run of the original synchronize event still requires fresh approval; run the subsequent label event instead.
82
+ The guard's assumption is that **workers never apply or remove `cert-review-approved`; only a lane coordinator does, after reading the certification-path change**. The permission API cannot distinguish a coordinator from a worker: all agents act as `trieloff`, an admin. Coordinator-only labelling is therefore a **procedural assumption**, not something the permission check enforces. Approval is **head-bound, cleared on any later push**. On `synchronize`, the guard compares the latest label application with the current head's server-side arrival before invalidating it. An old application (not newer than that arrival) is removed automatically and a touched PR is blocked until its new head is approved. If the coordinator already approved the new head after the push but before a delayed synchronize job starts, the label is **kept** and the ordinary admin/maintain permission check still applies. A permission lookup failure leaves that newer label in place but returns `INCOMPLETE`; keeping the label is not itself approval. If arrival/timing evidence is unavailable, the guard conservatively removes the label, returns `INCOMPLETE`, and records that reason. This is deliberately strict even when the PR does not touch certification paths: a present label with unknown timing is still invalidated and returns `INCOMPLETE`. A known stale label on an untouched PR is removed without blocking that PR (`PASS`). A failed removal is also red `INCOMPLETE`. This automated invalidation is not permission for workers to change the label manually. Re-running an old synchronize event does not clear a newer head-bound approval.
83
83
 
84
84
  On `merge_group`, the guard walks the first-parent merge ancestry from `head_sha` back to `base_sha`, resolves each merge's second parent to exactly one open PR, and inspects that member's actual merged delta. It checks approval against that queued head, not just whatever head the PR API currently returns. A moved head, an unexplained non-merge commit or an unapproved certification-path PR makes the group red. This assumes the queue's **merge-commit method** with two-parent synthetic merges; squash/rebase or any other unexplained ancestry fails closed. It does not call an LLM or run candidate code.
85
85
 
@@ -130,7 +130,7 @@ Outputs are `status` (`PASS`, `FAIL`, `INCOMPLETE`), `touched` and a structured
130
130
 
131
131
  A `pull_request` workflow can be deliberately rewritten to skip the guard, change its inputs or fabricate a status. This is an accidental-self-certification guard, **not** an organization-required-workflow security boundary. Pinning the action stops accidental use of the PR's implementation but does not force a candidate-controlled workflow to call it. Ruleset changes or an organization-required workflow are a separate owner decision.
132
132
 
133
- The committed public CLI integration regressions use real git repositories and a fake GitHub HTTP API. Run only this non-browser suite locally with `node --test test/integration/cert-self-guard.test.mjs`; CI also runs it with the full integration suite. It covers touched/untouched changes, a self-passing workflow/pin edit, rename paths, label timing against **server-side arrival** (including a backdated committer date), permission, approval followed by a push, API refusal and groups containing an unapproved or stale PR.
133
+ The committed public CLI integration regressions use real git repositories and a fake GitHub HTTP API. Run only this non-browser suite locally with `node --test test/integration/cert-self-guard.test.mjs`; CI also runs it with the full integration suite. It covers touched/untouched changes, a self-passing workflow/pin edit, rename paths, label timing against **server-side arrival** (including a backdated committer date), permission, approval followed by a push, delayed synchronize preserving a post-push approval, unknown arrival causing conservative invalidation, API refusal and groups containing an unapproved or stale PR.
134
134
 
135
135
  ## Which unit tests a commit runs
136
136
 
@@ -198,7 +198,7 @@ test('boots', async (t) => {
198
198
  | `profile` | Record a CPU profile of every target, sampled every 100 µs | `true` if `SLICC_PROFILE=1`, else `false` |
199
199
  | `realistic` | Run Chrome as a user would: headed, and without `--disable-background-timer-throttling`, `--disable-backgrounding-occluded-windows` and `--disable-renderer-backgrounding`, so a tab behind another one is hidden and throttled. For measuring background tabs. It needs a display: on CI, run the tests under `xvfb-run -a` | `false` |
200
200
 
201
- `chrome.page(t)` opens a tab and returns the page API: `goto(path)`, `reload()`, `evaluate(fn, ...args)`, `until(fn, ...args)`, `press(key, ...modifiers)` (a key name like `Enter` or `F5`, or a single character typed with its US-layout key code), `type(text)`, `insert(text)`, `enter()`, `init(fn)` (runs in every new document), `expose(name, handler)` (a binding the page calls with a JSON string), `screenshot(file)`, `tab()` (another tab in the same context), `close()`, `send(method, params, ms)` (a raw CDP call in the tab's session), `errors`, `responses` and `dir` (the test's artifact directory). `chrome.pid` is the browser's process id and `chrome.profile` its `slicc-harness-*` profile directory in `$TMPDIR`. `goto` and `reload` wait until the new document is complete and no longer `about:blank`, and retry the navigation once if that never happens. `until` polls until the function returns a truthy value (not only strict `true`) and resolves with that value; the timeout error names the last result. `within(ms, fn, ...args)` is `until` with its own deadline, for a stage that should take a known time. Both stop at the deadline even if one evaluation never answers. Every CDP call has a deadline: `connect(url).send(method, params, sessionId, ms)` rejects with `<method>: no answer in <ms> ms` (60 s unless given), so a stuck page fails its test instead of hanging the run. A crash fails it at once instead:
201
+ `chrome.page(t)` opens a tab and returns the page API: `goto(path)`, `reload()`, `evaluate(fn, ...args)`, `until(fn, ...args)`, `press(key, ...modifiers)` (a key name like `Enter` or `F5`, or a single character typed with its US-layout key code), `type(text)`, `insert(text)`, `enter()`, `init(fn)` (runs in every new document), `expose(name, handler)` (a binding the page calls with a JSON string), `screenshot(file)`, `tab()` (another tab in the same context), `close()`, `send(method, params, ms)` (a raw CDP call in the tab's session), `errors`, `responses` and `dir` (the test's artifact directory). `chrome.pid` is the browser's process id and `chrome.profile` its `slicc-harness-*` profile directory in `$TMPDIR`. `goto` and `reload` wait until the new document is complete and no longer `about:blank`, and retry the navigation once if that never happens. `until` polls until the function returns a truthy value (not only strict `true`) and resolves with that value; the timeout error names the last result. `within(ms, fn, ...args)` is `until` with its own deadline, for a stage that should take a known time. `run(fn, ...args)` or `run(options, fn, ...args)` is for a job that may outlast the `timeout`: it starts `fn` in the page without holding a `Runtime.evaluate` open, then polls it every `everyMs` (1 s) with short evaluates, and resolves or rejects with the job's own result. It decides slow from hung by progress, not by the clock. Progress is a change in `marker` (a function run in the page at each poll, such as `() => window.done`) or in what `progress` returns (an async function run in Node, such as a probe of a process tree's CPU time). With either one set, a job whose progress stays the same for `quietMs` (60 s) fails with `<label>: no progress for N s after M s`, the last marker and progress values, and the page's pending requests and navigations. `maxMs` (30 min) is the outer bound for a job that keeps moving but never ends. Without a `marker` or `progress` only `maxMs` applies. `label` defaults to the start of `fn`'s source. The job's value must survive `returnByValue`, as with `evaluate`. Both stop at the deadline even if one evaluation never answers. Every CDP call has a deadline: `connect(url).send(method, params, sessionId, ms)` rejects with `<method>: no answer in <ms> ms` (60 s unless given), so a stuck page fails its test instead of hanging the run. A crash fails it at once instead:
202
202
  - when the browser dies, every pending and later call rejects with `<method>: browser exited with <signal>` (or `with code <n>`);
203
203
  - when a renderer crashes, every pending and later call to that target, and to the dedicated workers it started, rejects with `<method>: page renderer crashed (<status>, code <n>) at <url>` (or `worker`, `shared worker`, `service worker`), and `console.log` gets the same line;
204
204
  - `until`, `within`, `goto` and `reload` stop retrying and rethrow it;
package/harness/page.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { writeFile } from 'node:fs/promises';
2
2
  import { flights } from './flight.mjs';
3
+ import { runner } from './run.mjs';
3
4
  import { sleep } from './util.mjs';
4
5
 
5
6
  const masks = { alt: 1, ctrl: 2, meta: 4, shift: 8 };
@@ -153,6 +154,23 @@ export function page(
153
154
  return run(fn, args, timeout);
154
155
  }
155
156
 
157
+ async function expression(source, ms) {
158
+ const { result, exceptionDetails } = await send(
159
+ 'Runtime.evaluate',
160
+ { expression: source, awaitPromise: true, returnByValue: true },
161
+ ms
162
+ );
163
+ if (exceptionDetails) throw new Error(exceptionDetails.exception?.description);
164
+ return decoded(result);
165
+ }
166
+
167
+ const job = runner({
168
+ expression,
169
+ timeout,
170
+ pending: () => flying.pending(),
171
+ capture: stall ? capture : undefined,
172
+ });
173
+
156
174
  async function within(ms, fn, ...args) {
157
175
  const deadline = Date.now() + ms;
158
176
  let last;
@@ -208,6 +226,7 @@ export function page(
208
226
  dispose,
209
227
  send,
210
228
  evaluate,
229
+ run: job,
211
230
  until,
212
231
  within,
213
232
  probed: () => Promise.all(probes),
@@ -0,0 +1,114 @@
1
+ import { sleep } from './util.mjs';
2
+
3
+ const RUN_EVERY = 1000;
4
+ const RUN_POLL = 10000;
5
+ const RUN_QUIET = 60000;
6
+ const RUN_MAX = 30 * 60 * 1000;
7
+
8
+ const unanswered = (error) => /: no answer in \d+ ms$/.test(error.message);
9
+ const seconds = (ms) => `${Math.round(ms / 1000)} s`;
10
+
11
+ export function started(source, args) {
12
+ return `(() => {
13
+ const runs = (globalThis.sliccHarnessRuns ??= []);
14
+ const slot = { done: false };
15
+ runs.push(slot);
16
+ Promise.resolve()
17
+ .then(() => (${source})(...${JSON.stringify(args)}))
18
+ .then(
19
+ (value) => Object.assign(slot, { done: true, value }),
20
+ (error) => Object.assign(slot, { done: true, error: String(error?.stack ?? error) })
21
+ );
22
+ return runs.length - 1;
23
+ })()`;
24
+ }
25
+
26
+ export function polled(id, marker) {
27
+ const mark = marker
28
+ ? `(() => { try { return (${marker})(); } catch (error) { return 'marker threw ' + error; } })()`
29
+ : 'null';
30
+ return `(() => {
31
+ const slot = globalThis.sliccHarnessRuns?.[${id}];
32
+ if (!slot) throw new Error('the page lost the run (it navigated or reloaded)');
33
+ if (slot.done) globalThis.sliccHarnessRuns[${id}] = { done: true };
34
+ return { ...slot, mark: ${mark} };
35
+ })()`;
36
+ }
37
+
38
+ function settings(first, rest) {
39
+ const direct = typeof first === 'function';
40
+ const options = direct ? {} : first;
41
+ const [fn, ...args] = direct ? [first, ...rest] : rest;
42
+ return {
43
+ fn,
44
+ args,
45
+ marker: options.marker,
46
+ progress: options.progress,
47
+ everyMs: options.everyMs ?? RUN_EVERY,
48
+ quietMs: options.quietMs ?? RUN_QUIET,
49
+ maxMs: options.maxMs ?? RUN_MAX,
50
+ label: options.label ?? String(fn).replace(/\s+/g, ' ').slice(0, 60),
51
+ };
52
+ }
53
+
54
+ async function poll(expression, source) {
55
+ try {
56
+ return await expression(source, RUN_POLL);
57
+ } catch (error) {
58
+ if (error.fatal || !unanswered(error)) throw error;
59
+ return undefined;
60
+ }
61
+ }
62
+
63
+ async function probed(progress) {
64
+ if (!progress) return null;
65
+ try {
66
+ return await progress();
67
+ } catch (error) {
68
+ return `threw ${error}`;
69
+ }
70
+ }
71
+
72
+ export function runner({ expression, timeout, pending, capture }) {
73
+ async function failure(run, last, why) {
74
+ if (capture) await capture().catch(() => undefined);
75
+ const lines = [`${run.label}: ${why}`];
76
+ if (run.marker !== undefined) lines.push(`last marker: ${JSON.stringify(last.mark)}`);
77
+ if (run.progress !== undefined) lines.push(`last progress: ${JSON.stringify(last.probe)}`);
78
+ const flying = pending();
79
+ lines.push(...(flying.length ? flying : ['nothing in flight']));
80
+ return new Error(lines.join('\n'));
81
+ }
82
+
83
+ return async function run(first, ...rest) {
84
+ const job = settings(first, rest);
85
+ const watched = job.marker !== undefined || job.progress !== undefined;
86
+ const id = await expression(started(String(job.fn), job.args), timeout);
87
+ const source = polled(id, job.marker && String(job.marker));
88
+ const begun = Date.now();
89
+ const at = { seen: undefined, moved: begun, last: {} };
90
+ for (;;) {
91
+ await sleep(job.everyMs);
92
+ const state = await poll(expression, source);
93
+ if (state?.done) {
94
+ if (state.error !== undefined) throw new Error(state.error);
95
+ return state.value;
96
+ }
97
+ at.last = { mark: state ? state.mark : at.last.mark, probe: await probed(job.progress) };
98
+ const signature = JSON.stringify([at.last.mark, at.last.probe]);
99
+ const now = Date.now();
100
+ if (signature !== at.seen) Object.assign(at, { seen: signature, moved: now });
101
+ if (watched && now - at.moved >= job.quietMs) {
102
+ const why = `no progress for ${seconds(now - at.moved)} after ${seconds(now - begun)}`;
103
+ throw await failure(job, at.last, why);
104
+ }
105
+ if (now - begun >= job.maxMs) {
106
+ throw await failure(
107
+ job,
108
+ at.last,
109
+ `still running after ${seconds(now - begun)}, the outer bound`
110
+ );
111
+ }
112
+ }
113
+ };
114
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "1.22.0",
3
+ "version": "1.23.0",
4
4
  "description": "Shared Renovate, Biome, TypeScript, lefthook and GitHub Actions configuration, plus the CDP integration-test harness, for SLICC's web repos",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",