vouchington-tooling 0.54.0 → 0.56.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.
Files changed (55) hide show
  1. package/README.md +23 -0
  2. package/dist/cli/index.mjs +2 -2
  3. package/dist/cli/optional-peer.d.mts +5 -0
  4. package/dist/cli/optional-peer.mjs +17 -0
  5. package/dist/cli/story-coverage-lazy.d.mts +3 -0
  6. package/dist/cli/story-coverage-lazy.mjs +6 -0
  7. package/dist/gh-api-shell-quoting/logical-line.mjs +14 -74
  8. package/dist/mcp-server/policy-run.d.mts +2 -0
  9. package/dist/mcp-server/policy-run.mjs +6 -2
  10. package/dist/mcp-server/policy-spawn.d.mts +1 -0
  11. package/dist/mcp-server/policy-spawn.mjs +10 -2
  12. package/dist/playwright/browser-errors.d.mts +3 -2
  13. package/dist/playwright/browser-test.d.mts +4 -3
  14. package/dist/playwright/index.d.mts +2 -0
  15. package/dist/playwright/monitored-test-info.d.mts +14 -0
  16. package/dist/playwright/monitored-test-info.mjs +1 -0
  17. package/dist/playwright/test-lifecycle-reporter.d.mts +17 -1
  18. package/dist/playwright/test-lifecycle-reporter.mjs +23 -1
  19. package/dist/retrospective-transcript/codex-records.mjs +4 -0
  20. package/dist/retrospective-transcript/command-prefix.d.mts +1 -0
  21. package/dist/retrospective-transcript/command-prefix.mjs +1 -1
  22. package/dist/retrospective-transcript/command-segments.d.mts +1 -1
  23. package/dist/retrospective-transcript/command-segments.mjs +3 -48
  24. package/dist/retrospective-transcript/escalations.d.mts +6 -0
  25. package/dist/retrospective-transcript/escalations.mjs +34 -0
  26. package/dist/retrospective-transcript/format.mjs +13 -0
  27. package/dist/retrospective-transcript/index.mjs +2 -1
  28. package/dist/retrospective-transcript/malformed-record.d.mts +1 -0
  29. package/dist/retrospective-transcript/malformed-record.mjs +13 -0
  30. package/dist/retrospective-transcript/shared.d.mts +2 -1
  31. package/dist/retrospective-transcript/shared.mjs +1 -12
  32. package/dist/shell-parse/index.d.mts +2 -0
  33. package/dist/shell-parse/index.mjs +2 -0
  34. package/dist/shell-parse/shell-command-segments.d.mts +6 -0
  35. package/dist/shell-parse/shell-command-segments.mjs +26 -0
  36. package/dist/shell-parse/shell-tokenizer-operators.d.mts +2 -4
  37. package/dist/shell-parse/shell-tokenizer-operators.mjs +14 -4
  38. package/dist/shell-parse/shell-tokenizer.d.mts +9 -5
  39. package/dist/shell-parse/shell-tokenizer.mjs +5 -1
  40. package/dist/shell-parse/shell-walk.d.mts +8 -0
  41. package/dist/shell-parse/shell-walk.mjs +62 -0
  42. package/dist/vitest-diagnostics/browser.d.mts +2 -0
  43. package/dist/vitest-diagnostics/browser.mjs +6 -0
  44. package/dist/vitest-diagnostics/index.d.mts +5 -22
  45. package/dist/vitest-diagnostics/index.mjs +3 -123
  46. package/dist/vitest-diagnostics/report-summary.d.mts +22 -0
  47. package/dist/vitest-diagnostics/report-summary.mjs +123 -0
  48. package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.d.mts +9 -2
  49. package/dist/vitest-diagnostics/vitest-fork-leak-diagnostics.mjs +3 -2
  50. package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.d.mts +5 -0
  51. package/dist/vitest-diagnostics/vitest-fork-leak-handshake-samples.mjs +5 -0
  52. package/dist/vitest-diagnostics/vitest-process-resources.d.mts +4 -0
  53. package/dist/vitest-diagnostics/vitest-process-resources.mjs +4 -1
  54. package/package.json +6 -1
  55. package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
package/README.md CHANGED
@@ -563,6 +563,17 @@ case it prints the multi-line report and optional pool metrics. `waitForForkLeak
563
563
  waits for a caller-supplied pool snapshot to settle. `installTestNetworkAllowlist` takes the
564
564
  allowed hosts, an exempt predicate, and the state key. `checkAndRestoreFakeTimers` restores real
565
565
  timers and returns a diagnostic when a test left fake timers installed.
566
+ `countResourcesByType` turns resource names into per-type counts and `recordForkLeakCheckpoint`
567
+ feeds a handshake settlement's counts to a detector. `formatForkLeakDiagnostics` takes an optional
568
+ fourth argument, `{ poolMetricsLabel }`, to replace the default `pool metrics:` label (for example
569
+ `'PostgreSQL pool metrics:'`).
570
+
571
+ `vouchington-tooling/vitest-diagnostics/browser` is the browser-safe entry for Storybook and Vitest
572
+ browser projects, for example a root fake-timer setup file shared with a Node project. It exports
573
+ only `checkAndRestoreFakeTimers`, `formatFakeTimerLeakDiagnostics`, and the `FakeTimerController`
574
+ type, and its import graph contains no `node:*` imports (a test enforces this), so it needs no Vite
575
+ `optimizeDeps` entry. The resource, fork-leak, reporter, and network-allowlist helpers stay in the
576
+ Node entry, and the effective-timeout cap is a config-time plugin that belongs in Node config.
566
577
 
567
578
  Use a caller-owned run directory: the reporter clears only regular numeric PID `.jsonl` files
568
579
  there at construction and leaves the directory and other files alone. Application metrics and CI artifact handling stay with the caller.
@@ -596,6 +607,18 @@ random suffixes, viewport sizes, a 1x1 PNG fixture, RFC 6238 TOTP codes, and a t
596
607
  reporter. The reporter prints one JSON line per test with the marker `playwright-test-lifecycle`.
597
608
  `@playwright/test` is an optional peer. TOTP setup and cleanup stay with the caller.
598
609
 
610
+ `createBrowserErrorsFixture`, `withMonitoredPage`, and `BrowserIssueMonitor` take the narrow
611
+ exported `MonitoredTestInfo` type (`attach`, `status`, `expectedStatus`, `timeout`) instead of
612
+ Playwright's full `TestInfo`. A real `TestInfo` is assignable to it, so no cast is needed.
613
+
614
+ `TestLifecycleReporter` accepts `failOnSkippedTests`, a plain boolean that defaults to `false`; the
615
+ reporter never reads `process.env.CI`, so the caller opts in explicitly:
616
+ `reporter: [[TestLifecycleReporter.modulePath, { failOnSkippedTests: Boolean(process.env.CI) }]]`.
617
+ When enabled, a run that would otherwise pass fails through the reporter's `onEnd` result status,
618
+ and stderr lists each skipped test's title path and `file:line`. Every test whose latest attempt
619
+ is `skipped` counts, including `test.fixme`, `test.skip`, and runtime `test.skip()`, because
620
+ Playwright reports all of them as `skipped`. A run that already failed keeps its status.
621
+
599
622
  `browser-session-runner` supervises caller-created browser-test processes. Callers supply command
600
623
  construction, line classification, retry/outcome policy, and budgets; the library owns process-group
601
624
  termination, output line buffering, shared deadlines, progress watchdogs, diagnostics, and parent signals.
@@ -6,7 +6,6 @@ import { runPostReviewCli } from "../gha-post-review/cli.mjs";
6
6
  import { runStageReviewPayloadCli } from "../gha-review-payload/cli.mjs";
7
7
  import { runSwiftSemanticEqualCli } from "../swift-semantic-equal/cli.mjs";
8
8
  import { runGhaArtifactsCleanup } from "./commands/gha-artifacts-cleanup.mjs";
9
- import { runStoryCoverage } from "./commands/story-coverage.mjs";
10
9
  import { runGhaRuntimeAudit } from "./commands/gha-runtime-audit.mjs";
11
10
  import { runHttpOrigin } from "./commands/http-origin.mjs";
12
11
  import { runPnpmInstallCli } from "./commands/pnpm-install.mjs";
@@ -31,6 +30,7 @@ import { runAstGrepPackCommand } from "./commands/ast-grep-pack.mjs";
31
30
  import { runGhaWorkspacePolicy } from "./commands/gha-workspace-policy.mjs";
32
31
  import { readInstalledVersion } from "./installed-version.mjs";
33
32
  import { parseCli } from "./parse.mjs";
33
+ import { runStoryCoverageLazy } from "./story-coverage-lazy.mjs";
34
34
  import { packageScriptPath } from "./script-path.mjs";
35
35
  import { commandUsage, printUsage } from "./usage.mjs";
36
36
  const SCRIPT_PATHS = {
@@ -130,7 +130,7 @@ export function runCli(argv = process.argv) {
130
130
  case 'gha-artifacts-cleanup':
131
131
  return runGhaArtifactsCleanup(parsed);
132
132
  case 'story-coverage':
133
- return runStoryCoverage(parsed);
133
+ return runStoryCoverageLazy(parsed);
134
134
  case 'retrospective-transcript':
135
135
  return runRetrospectiveTranscriptCommand(parsed.args);
136
136
  case 'link-skill':
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Loads a command module that value-imports an optional peer dependency. A missing peer becomes
3
+ * an actionable error; any other load failure is rethrown unchanged.
4
+ */
5
+ export declare function loadWithOptionalPeer<T>(command: string, peer: string, load: () => Promise<T>): Promise<T>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Loads a command module that value-imports an optional peer dependency. A missing peer becomes
3
+ * an actionable error; any other load failure is rethrown unchanged.
4
+ */
5
+ export async function loadWithOptionalPeer(command, peer, load) {
6
+ try {
7
+ return await load();
8
+ }
9
+ catch (error) {
10
+ if (error.code === 'ERR_MODULE_NOT_FOUND' &&
11
+ error instanceof Error &&
12
+ error.message.includes(`'${peer}'`)) {
13
+ throw new Error(`${command} requires the optional peer dependency ${peer}; install it alongside vouchington-tooling`, { cause: error });
14
+ }
15
+ throw error;
16
+ }
17
+ }
@@ -0,0 +1,3 @@
1
+ import type { ParsedStoryCoverage } from './parse-story-coverage.mts';
2
+ /** story-coverage value-imports the optional peer no-mistakes, so it loads only when dispatched. */
3
+ export declare function runStoryCoverageLazy(parsed: ParsedStoryCoverage): Promise<number>;
@@ -0,0 +1,6 @@
1
+ import { loadWithOptionalPeer } from "./optional-peer.mjs";
2
+ /** story-coverage value-imports the optional peer no-mistakes, so it loads only when dispatched. */
3
+ export async function runStoryCoverageLazy(parsed) {
4
+ const { runStoryCoverage } = await loadWithOptionalPeer('story-coverage', 'no-mistakes', () => import("./commands/story-coverage.mjs"));
5
+ return runStoryCoverage(parsed);
6
+ }
@@ -1,3 +1,4 @@
1
+ import { walkUnquotedShell } from "../shell-parse/index.mjs";
1
2
  import { consumeArgumentCharacter } from "./argument-scan.mjs";
2
3
  const GH_API_BOUNDARY = /[\s;|&(){}]/;
3
4
  const GH_API_HEAD = /^gh[ \t]+api\b/;
@@ -7,84 +8,23 @@ function matchGhApiHead(text, index) {
7
8
  const match = GH_API_HEAD.exec(text.slice(index));
8
9
  return match ? match[0].length : 0;
9
10
  }
10
- function newFrame() {
11
- return { inSingleQuote: false, inDoubleQuote: false, scanningArgs: false, parenDepth: 0 };
12
- }
13
- function pushSubstitutionFrame(stack) {
14
- const frame = newFrame();
15
- frame.parenDepth = 1;
16
- stack.push(frame);
17
- }
18
11
  // Scans one already-joined logical line for `gh api` calls and returns at most one hit per call —
19
12
  // the first unquoted `?` or `&`, whichever comes first. `offsets[k]` maps character k of `text`
20
13
  // back to its absolute offset in the original source, so callers can report real line numbers.
14
+ // Quote, escape, comment, and `$(...)` nesting state comes from `walkUnquotedShell`, which keeps
15
+ // each substitution level independent (`VAR="$(gh api "…?a=1&b=2")"` is a common idiom) and, unlike
16
+ // the shell tokenizer, does not treat a quoted `${VAR}` as making a later `?` unquoted.
21
17
  export function scanLogicalLine(text, offsets) {
22
18
  const hits = [];
23
- const stack = [newFrame()];
24
- let i = 0;
25
- while (i < text.length) {
26
- const frame = stack[stack.length - 1];
27
- const char = text[i];
28
- if (frame.inSingleQuote) {
29
- if (char === "'")
30
- frame.inSingleQuote = false;
31
- i += 1;
32
- continue;
33
- }
34
- if (char === '\\') {
35
- i += 2;
36
- continue;
37
- }
38
- if (frame.inDoubleQuote) {
39
- if (char === '"') {
40
- frame.inDoubleQuote = false;
41
- i += 1;
42
- continue;
43
- }
44
- if (char === '$' && text[i + 1] === '(') {
45
- pushSubstitutionFrame(stack);
46
- i += 2;
47
- continue;
48
- }
49
- i += 1;
50
- continue;
51
- }
52
- if (char === '#' && (i === 0 || /\s/.test(text[i - 1])))
53
- break;
54
- if (char === "'") {
55
- frame.inSingleQuote = true;
56
- i += 1;
57
- continue;
58
- }
59
- if (char === '"') {
60
- frame.inDoubleQuote = true;
61
- i += 1;
62
- continue;
63
- }
64
- if (char === '$' && text[i + 1] === '(') {
65
- pushSubstitutionFrame(stack);
66
- i += 2;
67
- continue;
68
- }
69
- if (stack.length > 1 && (char === '(' || char === ')')) {
70
- frame.parenDepth += char === '(' ? 1 : -1;
71
- i += 1;
72
- if (frame.parenDepth === 0)
73
- stack.pop();
74
- continue;
75
- }
76
- const argumentIndex = consumeArgumentCharacter(text, i, frame, hits, offsets);
77
- if (argumentIndex !== undefined) {
78
- i = argumentIndex;
79
- continue;
80
- }
81
- const headLength = frame.scanningArgs ? 0 : matchGhApiHead(text, i);
82
- if (headLength > 0) {
83
- frame.scanningArgs = true;
84
- i += headLength;
85
- continue;
86
- }
87
- i += 1;
88
- }
19
+ walkUnquotedShell(text, () => ({ scanningArgs: false }), (index, frame) => {
20
+ const argumentIndex = consumeArgumentCharacter(text, index, frame, hits, offsets);
21
+ if (argumentIndex !== undefined)
22
+ return argumentIndex;
23
+ const headLength = frame.scanningArgs ? 0 : matchGhApiHead(text, index);
24
+ if (headLength === 0)
25
+ return undefined;
26
+ frame.scanningArgs = true;
27
+ return index + headLength;
28
+ });
89
29
  return hits;
90
30
  }
@@ -22,6 +22,8 @@ export type PolicyRun = {
22
22
  env: NodeJS.ProcessEnv;
23
23
  /** Test seam: replaces the real child process. */
24
24
  spawn?: PolicySpawner;
25
+ /** Test seam: replaces `process.execPath` as the Node binary to launch. */
26
+ nodePath?: string;
25
27
  };
26
28
  /**
27
29
  * Runs one export of the worktree's declared policy module in a fresh child process (never in
@@ -1,6 +1,7 @@
1
+ import { existsSync } from 'node:fs';
1
2
  import { fileURLToPath } from 'node:url';
2
3
  import { resolvePolicyModule } from "./policy-config.mjs";
3
- import { policyEnvironment, spawnPolicy, } from "./policy-spawn.mjs";
4
+ import { missingNodeError, policyEnvironment, spawnPolicy, } from "./policy-spawn.mjs";
4
5
  /** How long each policy export may run before its process is killed, in milliseconds. */
5
6
  export const POLICY_TIMEOUTS_MS = {
6
7
  validateRetrospective: 30_000,
@@ -83,9 +84,12 @@ async function runUnscrubbed(run, spawn) {
83
84
  const module = await resolvePolicyModule(run.worktree);
84
85
  if (module === undefined)
85
86
  return { status: 'no-policy' };
87
+ const node = run.nodePath ?? process.execPath;
88
+ if (!existsSync(node))
89
+ throw missingNodeError(node);
86
90
  const timeoutMs = POLICY_TIMEOUTS_MS[name];
87
91
  const outcome = await spawn({
88
- command: process.execPath,
92
+ command: node,
89
93
  args: [RUNNER, module],
90
94
  cwd: run.worktree,
91
95
  env: policyEnvironment(run.env),
@@ -16,6 +16,7 @@ export type PolicyOutcome = {
16
16
  overflowed: boolean;
17
17
  };
18
18
  export type PolicySpawner = (request: PolicyRequest) => Promise<PolicyOutcome>;
19
+ export declare function missingNodeError(node: string): Error;
19
20
  /**
20
21
  * The child's whole environment. Blackboard credentials and NODE_OPTIONS are never passed; GitHub
21
22
  * tokens are passed only when the server has them, for the checks that call `gh`.
@@ -1,6 +1,9 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { accessSync, constants } from 'node:fs';
2
+ import { accessSync, constants, existsSync } from 'node:fs';
3
3
  import { delimiter, dirname, join } from 'node:path';
4
+ export function missingNodeError(node) {
5
+ return new Error(`The MCP server's Node binary (${node}) was removed, likely by a Node version upgrade. Reconnect the server: \`/mcp\` in Claude Code, or restart Codex.`);
6
+ }
4
7
  function isExecutable(path) {
5
8
  try {
6
9
  accessSync(path, constants.X_OK);
@@ -79,7 +82,12 @@ export const spawnPolicy = (request) => new Promise((resolve, reject) => {
79
82
  });
80
83
  child.on('error', (error) => {
81
84
  clearTimeout(timer);
82
- reject(error);
85
+ // ENOENT also means a missing cwd, so only a binary that is gone gets the reconnect message.
86
+ reject(error.code === 'ENOENT' &&
87
+ request.command === process.execPath &&
88
+ !existsSync(request.command)
89
+ ? missingNodeError(request.command)
90
+ : error);
83
91
  });
84
92
  // Reap anything the policy left running in its group as soon as the runner exits: a descendant
85
93
  // would otherwise keep the GitHub token it inherited, and one holding an inherited pipe would
@@ -1,5 +1,6 @@
1
- import type { BrowserContext, TestInfo } from '@playwright/test';
1
+ import type { BrowserContext } from '@playwright/test';
2
2
  import { type BrowserIssueAllowlistEntry } from './browser-issue-records.mts';
3
+ import type { MonitoredTestInfo } from './monitored-test-info.mts';
3
4
  interface BrowserIssueMonitorOptions {
4
5
  allowlist?: BrowserIssueAllowlistEntry[];
5
6
  warningPattern?: RegExp;
@@ -10,7 +11,7 @@ export declare class BrowserIssueMonitor {
10
11
  private readonly monitoredContexts;
11
12
  private readonly testInfo;
12
13
  private readonly warningPattern;
13
- constructor(testInfo: TestInfo, options?: BrowserIssueMonitorOptions);
14
+ constructor(testInfo: MonitoredTestInfo, options?: BrowserIssueMonitorOptions);
14
15
  monitorContext(context: BrowserContext): void;
15
16
  dispose(): void;
16
17
  attachIssuesIfAny(): Promise<boolean>;
@@ -1,5 +1,6 @@
1
- import { expect, type Browser, type BrowserContext, type Page, type TestInfo } from '@playwright/test';
1
+ import { expect, type Browser, type BrowserContext, type Page } from '@playwright/test';
2
2
  import { BrowserIssueMonitor } from './browser-errors.mts';
3
+ import type { MonitoredTestInfo } from './monitored-test-info.mts';
3
4
  import type { BrowserIssueAllowlistEntry } from './browser-issue-records.mts';
4
5
  import { type BlockedExternalNetworkRule } from './blocked-external-network.mts';
5
6
  export interface BrowserTestOptions {
@@ -14,8 +15,8 @@ interface BrowserErrorFixtures {
14
15
  }
15
16
  export declare function createBrowserErrorsFixture(options?: BrowserTestOptions): ({ context }: {
16
17
  context: BrowserContext;
17
- }, run: (monitor: BrowserIssueMonitor) => Promise<void>, testInfo: TestInfo) => Promise<void>;
18
+ }, run: (monitor: BrowserIssueMonitor) => Promise<void>, testInfo: MonitoredTestInfo) => Promise<void>;
18
19
  export declare function createBrowserTest(options?: BrowserTestOptions): import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & BrowserErrorFixtures, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
19
20
  export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & BrowserErrorFixtures, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
20
21
  export { expect };
21
- export declare function withMonitoredPage<T>(browserOrContext: Browser | BrowserContext, testInfo: TestInfo, callback: (page: Page) => Promise<T>, options?: BrowserTestOptions): Promise<T>;
22
+ export declare function withMonitoredPage<T>(browserOrContext: Browser | BrowserContext, testInfo: MonitoredTestInfo, callback: (page: Page) => Promise<T>, options?: BrowserTestOptions): Promise<T>;
@@ -9,6 +9,7 @@ export { BLOCKED_EXTERNAL_NETWORK_RULES, blockedExternalRequestFailureAllowlist,
9
9
  export type { BlockedExternalNetworkRule } from './blocked-external-network.mts';
10
10
  export { createBrowserErrorsFixture, createBrowserTest, expect, test, withMonitoredPage, } from './browser-test.mts';
11
11
  export type { BrowserTestOptions } from './browser-test.mts';
12
+ export type { MonitoredTestInfo } from './monitored-test-info.mts';
12
13
  export type { Browser, BrowserContext, Locator, Page, Request, TestInfo } from '@playwright/test';
13
14
  export { navigateTo } from './navigate-to.mts';
14
15
  export { retryOnConnectionLost } from './retry-on-connection-lost.mts';
@@ -25,6 +26,7 @@ export { randomSuffix } from './random-id.mts';
25
26
  export { storybookBundleHasStory } from './storybook.mts';
26
27
  export { TEST_PNG } from './test-fixtures.mts';
27
28
  export { TestLifecycleReporter };
29
+ export type { TestLifecycleReporterOptions } from './test-lifecycle-reporter.mts';
28
30
  export { generateTotpCode } from './totp.mts';
29
31
  export { DESKTOP_VIEWPORT, MOBILE_VIEWPORTS } from './viewport-constants.mts';
30
32
  export { setupVirtualAuthenticator } from './virtual-authenticator.mts';
@@ -0,0 +1,14 @@
1
+ import type { TestInfo } from '@playwright/test';
2
+ /**
3
+ * The members of Playwright's `TestInfo` that the browser-issue helpers read or call.
4
+ * A real `TestInfo` is assignable to it, and so is a small object literal.
5
+ */
6
+ export interface MonitoredTestInfo {
7
+ attach(name: string, options: {
8
+ body: Buffer;
9
+ contentType: string;
10
+ }): Promise<void>;
11
+ readonly expectedStatus: TestInfo['expectedStatus'];
12
+ readonly status?: TestInfo['status'];
13
+ readonly timeout: number;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,11 +1,27 @@
1
- import type { FullConfig, Reporter, TestCase, TestResult } from '@playwright/test/reporter';
1
+ import type { FullConfig, FullResult, Reporter, TestCase, TestResult } from '@playwright/test/reporter';
2
+ export interface TestLifecycleReporterOptions {
3
+ /**
4
+ * Fail the run when any test ends with status `skipped`. This includes `test.fixme`,
5
+ * `test.skip`, and tests skipped at runtime, because Playwright reports all of them as
6
+ * `skipped`. Defaults to `false`; the caller decides, for example
7
+ * `failOnSkippedTests: Boolean(process.env.CI)`.
8
+ */
9
+ failOnSkippedTests?: boolean;
10
+ }
2
11
  export default class TestLifecycleReporter implements Reporter {
3
12
  static readonly modulePath: string;
13
+ private readonly failOnSkippedTests;
14
+ private readonly skipped;
4
15
  private rootDir;
5
16
  private shard;
17
+ constructor(options?: TestLifecycleReporterOptions);
6
18
  onBegin(config: FullConfig): void;
7
19
  onTestBegin(test: TestCase, result: TestResult): void;
8
20
  onTestEnd(test: TestCase, result: TestResult): void;
21
+ onEnd(result: FullResult): Promise<{
22
+ status: FullResult['status'];
23
+ } | undefined>;
9
24
  printsToStdio(): boolean;
25
+ private relativeFile;
10
26
  private record;
11
27
  }
@@ -1,8 +1,13 @@
1
1
  import { relative } from 'node:path';
2
2
  export default class TestLifecycleReporter {
3
3
  static modulePath = import.meta.filename;
4
+ failOnSkippedTests;
5
+ skipped = new Map();
4
6
  rootDir = '';
5
7
  shard = null;
8
+ constructor(options = {}) {
9
+ this.failOnSkippedTests = options.failOnSkippedTests ?? false;
10
+ }
6
11
  onBegin(config) {
7
12
  this.rootDir = config.rootDir;
8
13
  this.shard = config.shard;
@@ -12,17 +17,34 @@ export default class TestLifecycleReporter {
12
17
  }
13
18
  onTestEnd(test, result) {
14
19
  this.record('end', test, result);
20
+ // Only a test's latest attempt counts: serial suites skip tests that a retry later runs.
21
+ if (result.status !== 'skipped') {
22
+ this.skipped.delete(test.id);
23
+ return;
24
+ }
25
+ const title = test.titlePath().filter(Boolean).join(' > ');
26
+ this.skipped.set(test.id, `${title} (${this.relativeFile(test)}:${test.location.line})`);
27
+ }
28
+ async onEnd(result) {
29
+ if (!this.failOnSkippedTests || this.skipped.size === 0)
30
+ return undefined;
31
+ const lines = [...this.skipped.values()].map((entry) => ` - ${entry}`).join('\n');
32
+ process.stderr.write(`${this.skipped.size} test(s) were skipped and failOnSkippedTests is enabled:\n${lines}\n`);
33
+ return result.status === 'passed' ? { status: 'failed' } : undefined;
15
34
  }
16
35
  printsToStdio() {
17
36
  return true;
18
37
  }
38
+ relativeFile(test) {
39
+ return relative(this.rootDir, test.location.file);
40
+ }
19
41
  record(event, test, result) {
20
42
  process.stdout.write(`${JSON.stringify({
21
43
  marker: 'playwright-test-lifecycle',
22
44
  event,
23
45
  observedAt: new Date().toISOString(),
24
46
  testId: test.id,
25
- file: relative(this.rootDir, test.location.file),
47
+ file: this.relativeFile(test),
26
48
  line: test.location.line,
27
49
  project: test.parent.project()?.name,
28
50
  shard: this.shard,
@@ -1,4 +1,5 @@
1
1
  import { CodexMessageCounter } from "./codex-messages.mjs";
2
+ import { escalationOf } from "./escalations.mjs";
2
3
  import { commands, hasFailedOutcome } from "./codex-payload.mjs";
3
4
  import { applyCommand, asNumber, asRecord, emptyTokens, } from "./shared.mjs";
4
5
  function usage(record) {
@@ -75,6 +76,9 @@ export function applyRecords(records, facts, subagent, baseline = emptyTokens())
75
76
  calls.add(id);
76
77
  if (payload.name === 'advisor')
77
78
  facts.advisorCalls++;
79
+ const escalation = escalationOf(payload);
80
+ if (escalation)
81
+ facts.escalations.push(escalation);
78
82
  for (const rawCommand of commands(payload))
79
83
  applyCommand(rawCommand, facts);
80
84
  }
@@ -1 +1,2 @@
1
+ export declare function redactOverlongToken(token: string): string;
1
2
  export declare function normalizeCommandPrefix(command: string): string;
@@ -11,7 +11,7 @@ import { isPackageRunner, splitCommandSegments } from "./command-segments.mjs";
11
11
  // for a privacy boundary, over-redacting a legitimate token is the safe failure mode.
12
12
  const MAX_COMMAND_TOKEN_LENGTH = 40;
13
13
  const REDACTED_TOKEN = '…';
14
- function redactOverlongToken(token) {
14
+ export function redactOverlongToken(token) {
15
15
  return token.length > MAX_COMMAND_TOKEN_LENGTH ? REDACTED_TOKEN : token;
16
16
  }
17
17
  const ENV_ASSIGNMENT_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*=/;
@@ -1,2 +1,2 @@
1
- export declare function splitCommandSegments(command: string): string[][];
1
+ export { splitCommandSegments } from '../shell-parse/index.mts';
2
2
  export declare function isPackageRunner(word: string | undefined): boolean;
@@ -1,51 +1,6 @@
1
- // Commands are matched by command position, not by scanning for words anywhere in
2
- // the string. The string is split into segments on unquoted `;`, `&`, `|` and
3
- // newlines (so `git push;gh pr view` splits even with no surrounding whitespace).
4
- // Quoted spans, including any whitespace inside them, are grouped into a single
5
- // word, mirroring real shell tokenization.
6
- export function splitCommandSegments(command) {
7
- const segments = [];
8
- let current = [];
9
- let word = '';
10
- let quote = null;
11
- const flushWord = () => {
12
- if (word) {
13
- current.push(word);
14
- word = '';
15
- }
16
- };
17
- const flushSegment = () => {
18
- flushWord();
19
- if (current.length) {
20
- segments.push(current);
21
- current = [];
22
- }
23
- };
24
- for (const char of command) {
25
- if (quote) {
26
- if (char === quote)
27
- quote = null;
28
- else
29
- word += char;
30
- continue;
31
- }
32
- if (char === '"' || char === "'") {
33
- quote = char;
34
- continue;
35
- }
36
- if (char === ';' || char === '&' || char === '|' || char === '\n' || char === '\r') {
37
- flushSegment();
38
- continue;
39
- }
40
- if (/\s/.test(char)) {
41
- flushWord();
42
- continue;
43
- }
44
- word += char;
45
- }
46
- flushSegment();
47
- return segments;
48
- }
1
+ // Commands are matched by command position, not by scanning for words anywhere in the string.
2
+ // Segmenting and quote handling belong to shell-parse.
3
+ export { splitCommandSegments } from "../shell-parse/index.mjs";
49
4
  const PACKAGE_RUNNERS = ['npx', 'pnpm', 'pnpx', 'yarn'];
50
5
  export function isPackageRunner(word) {
51
6
  if (!word)
@@ -0,0 +1,6 @@
1
+ export type SandboxEscalation = {
2
+ commandPrefix: string;
3
+ justification?: string;
4
+ prefixRule?: string[];
5
+ };
6
+ export declare function escalationOf(payload: Record<string, unknown>): SandboxEscalation | undefined;
@@ -0,0 +1,34 @@
1
+ import { normalizeCommandPrefix, redactOverlongToken } from "./command-prefix.mjs";
2
+ import { asRecord } from "./shared.mjs";
3
+ const MAX_JUSTIFICATION_LENGTH = 240;
4
+ // Only a parsed `exec_command` function_call whose JSON arguments request
5
+ // `sandbox_permissions: "require_escalated"` counts. Text that merely quotes the field
6
+ // (for example an auto-review prompt) never reaches here because it is not a call.
7
+ // The approval outcome is not recorded in a stable shape, so it is intentionally omitted.
8
+ export function escalationOf(payload) {
9
+ if (payload.type !== 'function_call' || payload.name !== 'exec_command')
10
+ return undefined;
11
+ if (typeof payload.arguments !== 'string')
12
+ return undefined;
13
+ let args;
14
+ try {
15
+ args = asRecord(JSON.parse(payload.arguments));
16
+ }
17
+ catch {
18
+ return undefined;
19
+ }
20
+ if (args?.sandbox_permissions !== 'require_escalated')
21
+ return undefined;
22
+ const command = args.cmd ?? args.command;
23
+ const justification = typeof args.justification === 'string'
24
+ ? args.justification.replace(/\s+/g, ' ').trim().slice(0, MAX_JUSTIFICATION_LENGTH)
25
+ : '';
26
+ const rule = Array.isArray(args.prefix_rule)
27
+ ? args.prefix_rule.filter((token) => typeof token === 'string')
28
+ : [];
29
+ return {
30
+ commandPrefix: typeof command === 'string' ? normalizeCommandPrefix(command) : '',
31
+ ...(justification ? { justification } : {}),
32
+ ...(rule.length ? { prefixRule: rule.map(redactOverlongToken) } : {}),
33
+ };
34
+ }
@@ -16,7 +16,20 @@ export function formatTranscriptFacts(sessionId, facts) {
16
16
  `Tokens: input=${facts.tokens.input} output=${facts.tokens.output} cache_read=${facts.tokens.cacheRead} cache_creation=${facts.tokens.cacheCreation}`,
17
17
  `Subagent tool calls: ${facts.subagentToolCalls}`,
18
18
  `Subagent tokens: input=${facts.subagentTokens.input} output=${facts.subagentTokens.output} cache_read=${facts.subagentTokens.cacheRead} cache_creation=${facts.subagentTokens.cacheCreation}`,
19
+ ...escalationLines(facts),
19
20
  '',
20
21
  ].join('\n');
21
22
  }
23
+ function escalationLines(facts) {
24
+ if (!facts.escalations.length)
25
+ return [];
26
+ return [
27
+ `Sandbox escalations: ${facts.escalations.length}`,
28
+ ...facts.escalations.map((item) => {
29
+ const rule = item.prefixRule ? ` prefix_rule=${JSON.stringify(item.prefixRule)}` : '';
30
+ const why = item.justification ? ` justification=${JSON.stringify(item.justification)}` : '';
31
+ return `- ${item.commandPrefix || '(unknown)'}${rule}${why}`;
32
+ }),
33
+ ];
34
+ }
22
35
  export const formatUnavailable = (reason) => `=== Transcript Facts ===\nStatus: unavailable (${reason.replace(/\s+/g, ' ').slice(0, 240)})\n`;
@@ -7,7 +7,8 @@ import { segmentCodex } from "./codex-segment.mjs";
7
7
  import { computeClaude } from "./claude.mjs";
8
8
  import { formatTranscriptFacts, formatUnavailable } from "./format.mjs";
9
9
  import { globFrom, resolveTranscriptFile, SESSION_ID, } from "./resolve-transcript-file.mjs";
10
- import { emptyFacts, hasMalformedInteriorRecord, parseLines, } from "./shared.mjs";
10
+ import { hasMalformedInteriorRecord } from "./malformed-record.mjs";
11
+ import { emptyFacts, parseLines } from "./shared.mjs";
11
12
  export { codexChildren, codexIdentity } from "./codex.mjs";
12
13
  export { formatTranscriptFacts, formatUnavailable } from "./format.mjs";
13
14
  export { resolveTranscriptFile } from "./resolve-transcript-file.mjs";
@@ -0,0 +1 @@
1
+ export declare function hasMalformedInteriorRecord(lines: string[]): boolean;
@@ -0,0 +1,13 @@
1
+ import { asRecord } from "./shared.mjs";
2
+ export function hasMalformedInteriorRecord(lines) {
3
+ const nonblank = lines.filter((line) => line.trim());
4
+ const complete = lines.at(-1)?.trim() ? nonblank.slice(0, -1) : nonblank;
5
+ return complete.some((line) => {
6
+ try {
7
+ return !asRecord(JSON.parse(line));
8
+ }
9
+ catch {
10
+ return true;
11
+ }
12
+ });
13
+ }
@@ -1,3 +1,4 @@
1
+ import type { SandboxEscalation } from './escalations.mts';
1
2
  export type TokenTotals = {
2
3
  input: number;
3
4
  output: number;
@@ -16,6 +17,7 @@ export type TranscriptFacts = {
16
17
  tokens: TokenTotals;
17
18
  subagentToolCalls: number;
18
19
  subagentTokens: TokenTotals;
20
+ escalations: SandboxEscalation[];
19
21
  };
20
22
  export type ParsedLine = Record<string, unknown>;
21
23
  export type CodexSegment = {
@@ -27,5 +29,4 @@ export declare const emptyFacts: () => TranscriptFacts;
27
29
  export declare function asRecord(value: unknown): ParsedLine | undefined;
28
30
  export declare const asNumber: (value: unknown) => number;
29
31
  export declare function parseLines(lines: string[]): ParsedLine[];
30
- export declare function hasMalformedInteriorRecord(lines: string[]): boolean;
31
32
  export declare function applyCommand(command: string, facts: TranscriptFacts): void;