vouchington-tooling 0.61.0 → 0.62.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
@@ -355,6 +355,7 @@ gone.
355
355
  ```ts
356
356
  import {
357
357
  isRunnerReservedPort,
358
+ listenOnLoopbackEphemeralPort,
358
359
  listenOnRunnerUnreservedEphemeralPort,
359
360
  runnerPortPolicy,
360
361
  } from 'vouchington-tooling/runner-port-policy'
@@ -667,6 +668,20 @@ feeds a handshake settlement's counts to a detector. `formatForkLeakDiagnostics`
667
668
  fourth argument, `{ poolMetricsLabel }`, to replace the default `pool metrics:` label (for example
668
669
  `'PostgreSQL pool metrics:'`).
669
670
 
671
+ `ciReporters(options?)` builds the Vitest `reporters` list from env vars, and `ciOutputFile(options?)`
672
+ builds `outputFile`. Unset or empty `VITEST_CI_REPORTERS` returns `undefined` (or `default` plus file
673
+ progress when `VITEST_DIAGNOSTICS=1`); `run` returns `minimal`, the optional Storybook progress
674
+ reporter (`VITEST_STORYBOOK_BROWSER=1`), `github-actions`, `junit`, `extraReporters`,
675
+ `hanging-process`, and file progress (stdout with `VITEST_DIAGNOSTICS=1`, appended to
676
+ `VITEST_FILE_PROGRESS_FILE` when set). Options: `env`, `envNames` (rename any variable; see
677
+ `DEFAULT_CI_REPORTER_ENV_NAMES`), `fileProgressPrefix`, `storybookProgressPrefix`, `extraReporters`
678
+ (for example a no-skips or teardown-overrun reporter), and `cwd`. The progress reporters print
679
+ `<prefix> event=start|finish module="..."` and `<prefix> seq=N event=module-*` lines; the defaults
680
+ are `[vitest-file]` and `[vitest-browser-progress]`, exported as `DEFAULT_FILE_PROGRESS_PREFIX` and
681
+ `DEFAULT_STORYBOOK_PROGRESS_PREFIX`. Pass the same prefix to `formatFileProgress`,
682
+ `formatStorybookProgressMarker`, and `latestStorybookProgressSequence(text, prefix)` when parsing.
683
+ These stay in the Node entry, never the browser entry.
684
+
670
685
  `vouchington-tooling/vitest-diagnostics/browser` is the browser-safe entry for Storybook and Vitest
671
686
  browser projects, for example a root fake-timer setup file shared with a Node project. It exports
672
687
  only `checkAndRestoreFakeTimers`, `formatFakeTimerLeakDiagnostics`, and the `FakeTimerController`
@@ -740,6 +755,12 @@ the dedicated process group to exit after the direct child closes so descendants
740
755
  `isProcessGroupAlive` and `waitForProcessGroupExit` are also available when callers need the same
741
756
  process-group probe and bounded-drain semantics outside a browser session.
742
757
 
758
+ `listenOnLoopbackEphemeralPort(server, options?)` from `runner-port-policy` binds an ephemeral port
759
+ outside the reserved runner range on IPv6 loopback (`::1`) and falls back to `127.0.0.1` only when the
760
+ host reports `EAFNOSUPPORT` (for example a kernel booted with `ipv6.disable=1`). Any other bind error is
761
+ rethrown. It resolves `{ host, port }` and accepts the same `EphemeralListenerOptions` (`isAllowedPort`,
762
+ `listen`, `maxBindAttempts`, `policy`) as `listenOnRunnerUnreservedEphemeralPort`, whose bind-retry loop it reuses.
763
+
743
764
  ### Generated arbiter input
744
765
 
745
766
  The `pg-schema-snapshot` export also provides `projectGeneratedArbiterInput(conflict)` for
@@ -3,6 +3,8 @@ export declare function isRecord(value: unknown): value is Record<string, unknow
3
3
  export declare function hookToolInput(payload: HookPayload): Record<string, unknown> | undefined;
4
4
  export declare function extractToolCommand(payload: HookPayload): string;
5
5
  export declare function hookToolName(payload: HookPayload): string;
6
+ /** A numeric `exit_code` from the response shapes that carry one; undefined otherwise. */
7
+ export declare function hookToolExitCode(payload: HookPayload): number | undefined;
6
8
  export declare function hookSessionId(payload: HookPayload): string;
7
9
  export declare function hookFilePath(payload: HookPayload): string;
8
10
  export declare function hookCwd(payload: HookPayload, fallback?: string): string;
@@ -26,6 +26,14 @@ function firstString(values) {
26
26
  export function hookToolName(payload) {
27
27
  return firstString([payload.tool_name, payload.toolName]);
28
28
  }
29
+ /** A numeric `exit_code` from the response shapes that carry one; undefined otherwise. */
30
+ export function hookToolExitCode(payload) {
31
+ for (const response of [payload.tool_response, payload.toolResponse, payload.toolResult]) {
32
+ if (isRecord(response) && typeof response.exit_code === 'number')
33
+ return response.exit_code;
34
+ }
35
+ return undefined;
36
+ }
29
37
  export function hookSessionId(payload) {
30
38
  return firstString([payload.session_id, payload.sessionId, payload.conversation_id]);
31
39
  }
@@ -20,6 +20,15 @@ export declare class EphemeralListenerAttemptsExhaustedError extends Error {
20
20
  export declare const runnerPortPolicy: RunnerPortPolicy;
21
21
  export declare function isRunnerReservedPort(port: number, policy?: RunnerPortPolicy): boolean;
22
22
  export declare function listenOnRunnerUnreservedEphemeralPort(server: Server, host: string, options?: EphemeralListenerOptions): Promise<number>;
23
+ export type LoopbackHost = '::1' | '127.0.0.1';
24
+ /**
25
+ * Binds `server` to an unreserved ephemeral port on IPv6 loopback, falling back to IPv4
26
+ * loopback only when the host has no IPv6 support (EAFNOSUPPORT). Other errors are rethrown.
27
+ */
28
+ export declare function listenOnLoopbackEphemeralPort(server: Server, options?: EphemeralListenerOptions): Promise<{
29
+ host: LoopbackHost;
30
+ port: number;
31
+ }>;
23
32
  export declare function loadRunnerPortPolicy(policyUrl?: URL): RunnerPortPolicy;
24
33
  export declare function validateRunnerPortPolicy(parsedPolicy: unknown, policyUrl?: URL): RunnerPortPolicy;
25
34
  export {};
@@ -26,6 +26,38 @@ export async function listenOnRunnerUnreservedEphemeralPort(server, host, option
26
26
  }
27
27
  throw new EphemeralListenerAttemptsExhaustedError(maxBindAttempts);
28
28
  }
29
+ /**
30
+ * Binds `server` to an unreserved ephemeral port on IPv6 loopback, falling back to IPv4
31
+ * loopback only when the host has no IPv6 support (EAFNOSUPPORT). Other errors are rethrown.
32
+ */
33
+ export async function listenOnLoopbackEphemeralPort(server, options = {}) {
34
+ const listen = options.listen ?? listenOnHost;
35
+ let ipv6Unsupported = false;
36
+ try {
37
+ const port = await listenOnRunnerUnreservedEphemeralPort(server, '::1', {
38
+ ...options,
39
+ listen: async (target, host) => {
40
+ try {
41
+ await listen(target, host);
42
+ }
43
+ catch (error) {
44
+ ipv6Unsupported =
45
+ error instanceof Error && 'code' in error && error.code === 'EAFNOSUPPORT';
46
+ throw error;
47
+ }
48
+ },
49
+ });
50
+ return { host: '::1', port };
51
+ }
52
+ catch (error) {
53
+ if (!ipv6Unsupported)
54
+ throw error;
55
+ return {
56
+ host: '127.0.0.1',
57
+ port: await listenOnRunnerUnreservedEphemeralPort(server, '127.0.0.1', options),
58
+ };
59
+ }
60
+ }
29
61
  export function loadRunnerPortPolicy(policyUrl = shippedPolicyUrl) {
30
62
  return validateRunnerPortPolicy(JSON.parse(readFileSync(policyUrl, 'utf8')), policyUrl);
31
63
  }
package/dist/tmux/cli.mjs CHANGED
@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs';
2
2
  import { runScript } from "../cli/commands/spawn-script.mjs";
3
3
  import { packageScriptPath } from "../cli/script-path.mjs";
4
4
  import { TMUX_USAGE } from "./cli-shared.mjs";
5
- import { parseHookPayload } from "./hook-payload.mjs";
5
+ import { parseHookPayload } from "../command-policy/hook/harness.mjs";
6
6
  import { renderPostToolReminder } from "./reminder-post-tool.mjs";
7
7
  import { runUp } from "./up.mjs";
8
8
  export { TMUX_USAGE };
@@ -1,4 +1,4 @@
1
- import { type HookPayload } from './hook-payload.mts';
1
+ import type { HookPayload } from '../command-policy/types.mts';
2
2
  export type PaneTitleSpawnResult = {
3
3
  error?: NodeJS.ErrnoException | null | undefined;
4
4
  status: number | null;
@@ -1,6 +1,6 @@
1
1
  import { spawnSync } from 'node:child_process';
2
2
  import { packageScriptPath } from "../cli/script-path.mjs";
3
- import { extractToolCommand, hookToolName, toolExitCode, } from "./hook-payload.mjs";
3
+ import { extractToolCommand, hookToolExitCode, hookToolName } from "../command-policy/payload.mjs";
4
4
  const PR_CREATE_COMMAND_PATTERN = /(^|[;&|])\s*gh\s+pr\s+create(\s|$)/;
5
5
  const GIT_PUSH_COMMAND_PATTERN = /(^|[;&|])\s*git\s+push(\s|$)/;
6
6
  const RESET_WORKTREE_PATTERN = /(^|[;&|])\s*(?:\S*\/)?reset-worktree(?:\.sh)?(?:\s+(--help|-h))?(?=[;&|]|\s|$)/g;
@@ -64,7 +64,7 @@ export function renderPostToolReminder(payload, options = {}) {
64
64
  if (!SHELL_TOOLS.has(toolName))
65
65
  return null;
66
66
  const command = extractToolCommand(payload);
67
- const exitCode = toolExitCode(payload);
67
+ const exitCode = hookToolExitCode(payload);
68
68
  if (command === '' || (exitCode !== undefined && exitCode !== 0))
69
69
  return null;
70
70
  if (PR_CREATE_COMMAND_PATTERN.test(command)) {
@@ -18,3 +18,11 @@ export type { ForkLeakDiagnosticsOptions } from './vitest-fork-leak-diagnostics.
18
18
  export type { ForkLeakDetector, ForkLeakDetectorOptions, ForkLeakVerdict, } from './vitest-fork-leak-detection.mts';
19
19
  export { DEFAULT_MAX_DIAGNOSTIC_REPORTS, DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS, formatDiagnosticReportSummaries, HARD_MAX_DIAGNOSTIC_REPORTS, MAX_DIAGNOSTIC_REPORT_BYTES, HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES, readDiagnosticReportSummaries, summarizeDiagnosticReport, } from './report-summary.mts';
20
20
  export type { DiagnosticReportLimitOptions, DiagnosticReportSummary } from './report-summary.mts';
21
+ export { DEFAULT_CI_REPORTER_ENV_NAMES, ciOutputFile, ciReporters } from './vitest-ci-reporters.mts';
22
+ export type { CiReporterEnvNames, CiReportersOptions, VitestReporter, VitestReporters, } from './vitest-ci-reporters.mts';
23
+ export { githubActionsReporter, normalizeGithubActionsPath, } from './vitest-github-actions-reporter.mts';
24
+ export type { GithubActionsEnv, NormalizeGithubActionsPathOptions, } from './vitest-github-actions-reporter.mts';
25
+ export { DEFAULT_FILE_PROGRESS_PREFIX, createFileProgressWriter, createVitestFileProgressReporter, formatFileProgress, isFileProgressReporter, } from './vitest-file-progress-reporter.mts';
26
+ export type { FileProgressEvent, FileProgressReporterOptions, WriteProgress, } from './vitest-file-progress-reporter.mts';
27
+ export { DEFAULT_STORYBOOK_PROGRESS_PREFIX, createVitestStorybookProgressReporter, formatStorybookProgressMarker, latestStorybookProgressSequence, } from './vitest-storybook-progress-reporter.mts';
28
+ export type { StorybookProgressEvent, StorybookProgressReporterOptions, } from './vitest-storybook-progress-reporter.mts';
@@ -9,3 +9,7 @@ export { FORK_LEAK_HANDSHAKE_MAX_TURNS, FORK_LEAK_HANDSHAKE_STABLE_OBSERVATIONS,
9
9
  export { countResourcesByType } from "./vitest-process-resources.mjs";
10
10
  export { recordForkLeakCheckpoint } from "./vitest-fork-leak-handshake-samples.mjs";
11
11
  export { DEFAULT_MAX_DIAGNOSTIC_REPORTS, DEFAULT_MAX_FORMATTED_DIAGNOSTIC_REPORTS, formatDiagnosticReportSummaries, HARD_MAX_DIAGNOSTIC_REPORTS, MAX_DIAGNOSTIC_REPORT_BYTES, HARD_MAX_DIAGNOSTIC_DIRECTORY_ENTRIES, readDiagnosticReportSummaries, summarizeDiagnosticReport, } from "./report-summary.mjs";
12
+ export { DEFAULT_CI_REPORTER_ENV_NAMES, ciOutputFile, ciReporters } from "./vitest-ci-reporters.mjs";
13
+ export { githubActionsReporter, normalizeGithubActionsPath, } from "./vitest-github-actions-reporter.mjs";
14
+ export { DEFAULT_FILE_PROGRESS_PREFIX, createFileProgressWriter, createVitestFileProgressReporter, formatFileProgress, isFileProgressReporter, } from "./vitest-file-progress-reporter.mjs";
15
+ export { DEFAULT_STORYBOOK_PROGRESS_PREFIX, createVitestStorybookProgressReporter, formatStorybookProgressMarker, latestStorybookProgressSequence, } from "./vitest-storybook-progress-reporter.mjs";
@@ -0,0 +1,40 @@
1
+ import type { InlineConfig } from 'vitest/node';
2
+ export type VitestReporters = NonNullable<InlineConfig['reporters']>;
3
+ export type VitestReporter = Extract<VitestReporters, readonly unknown[]>[number];
4
+ type VitestOutputFile = NonNullable<InlineConfig['outputFile']>;
5
+ type Env = Record<string, string | undefined>;
6
+ export interface CiReporterEnvNames {
7
+ /** Selects the reporter set: unset or empty for local, `run` for CI. */
8
+ reporters: string;
9
+ /** `1` streams file progress to stdout. */
10
+ diagnostics: string;
11
+ /** Path that buffers file progress when set. */
12
+ fileProgressFile: string;
13
+ /** `1` adds the Storybook progress reporter. */
14
+ storybookBrowser: string;
15
+ /** Path of the JUnit XML output file. */
16
+ junitOutputFile: string;
17
+ }
18
+ export declare const DEFAULT_CI_REPORTER_ENV_NAMES: CiReporterEnvNames;
19
+ export interface CiReportersOptions {
20
+ /** Environment to read; defaults to `process.env`. */
21
+ env?: Env;
22
+ /** Override any of the env var names. */
23
+ envNames?: Partial<CiReporterEnvNames>;
24
+ /** Marker prefix for file progress lines. */
25
+ fileProgressPrefix?: string;
26
+ /** Marker prefix for Storybook progress lines. */
27
+ storybookProgressPrefix?: string;
28
+ /** Extra reporters inserted in `run` mode after `junit` (for example no-skips or teardown). */
29
+ extraReporters?: readonly VitestReporter[];
30
+ /** Working directory for the `github-actions` reporter's path normalization. */
31
+ cwd?: string;
32
+ }
33
+ /**
34
+ * Builds the Vitest reporter list from env vars, or `undefined` for the default reporters.
35
+ * File progress streams to stdout when diagnostics are on and is appended to the progress file
36
+ * when set. Throws for an unknown reporter-set value.
37
+ */
38
+ export declare function ciReporters(options?: CiReportersOptions): VitestReporters | undefined;
39
+ export declare function ciOutputFile(options?: CiReportersOptions): VitestOutputFile | undefined;
40
+ export {};
@@ -0,0 +1,70 @@
1
+ import { githubActionsReporter } from "./vitest-github-actions-reporter.mjs";
2
+ import { createFileProgressWriter, createVitestFileProgressReporter, } from "./vitest-file-progress-reporter.mjs";
3
+ import { createVitestStorybookProgressReporter } from "./vitest-storybook-progress-reporter.mjs";
4
+ export const DEFAULT_CI_REPORTER_ENV_NAMES = {
5
+ reporters: 'VITEST_CI_REPORTERS',
6
+ diagnostics: 'VITEST_DIAGNOSTICS',
7
+ fileProgressFile: 'VITEST_FILE_PROGRESS_FILE',
8
+ storybookBrowser: 'VITEST_STORYBOOK_BROWSER',
9
+ junitOutputFile: 'VITEST_JUNIT_OUTPUT_FILE',
10
+ };
11
+ function resolveNames(options) {
12
+ return { ...DEFAULT_CI_REPORTER_ENV_NAMES, ...options.envNames };
13
+ }
14
+ function fileProgress(prefix, write) {
15
+ return createVitestFileProgressReporter({
16
+ ...(write ? { write } : {}),
17
+ ...(prefix ? { prefix } : {}),
18
+ });
19
+ }
20
+ function fileProgressReporters(env, names, prefix) {
21
+ const progressFile = env[names.fileProgressFile];
22
+ const toFile = progressFile ? createFileProgressWriter(progressFile) : undefined;
23
+ const toStdout = env[names.diagnostics] === '1';
24
+ if (!toFile && !toStdout)
25
+ return [];
26
+ if (!toFile)
27
+ return [fileProgress(prefix)];
28
+ if (!toStdout)
29
+ return [fileProgress(prefix, toFile)];
30
+ return [fileProgress(prefix), fileProgress(prefix, toFile)];
31
+ }
32
+ /**
33
+ * Builds the Vitest reporter list from env vars, or `undefined` for the default reporters.
34
+ * File progress streams to stdout when diagnostics are on and is appended to the progress file
35
+ * when set. Throws for an unknown reporter-set value.
36
+ */
37
+ export function ciReporters(options = {}) {
38
+ const env = options.env ?? process.env;
39
+ const names = resolveNames(options);
40
+ const prefix = options.fileProgressPrefix;
41
+ const selected = env[names.reporters];
42
+ switch (selected) {
43
+ case undefined:
44
+ case '':
45
+ return env[names.diagnostics] === '1' ? ['default', fileProgress(prefix)] : undefined;
46
+ case 'run':
47
+ return [
48
+ 'minimal',
49
+ ...(env[names.storybookBrowser] === '1'
50
+ ? [
51
+ createVitestStorybookProgressReporter(options.storybookProgressPrefix ? { prefix: options.storybookProgressPrefix } : {}),
52
+ ]
53
+ : []),
54
+ githubActionsReporter({
55
+ env,
56
+ ...(options.cwd ? { cwd: options.cwd } : {}),
57
+ }),
58
+ 'junit',
59
+ ...(options.extraReporters ?? []),
60
+ 'hanging-process',
61
+ ...fileProgressReporters(env, names, prefix),
62
+ ];
63
+ default:
64
+ throw new Error(`Unknown ${names.reporters} value "${selected}". Accepted value: run.`);
65
+ }
66
+ }
67
+ export function ciOutputFile(options = {}) {
68
+ const junit = (options.env ?? process.env)[resolveNames(options).junitOutputFile];
69
+ return junit ? { junit } : undefined;
70
+ }
@@ -0,0 +1,24 @@
1
+ import type { Reporter, TestModule } from 'vitest/node';
2
+ export declare const DEFAULT_FILE_PROGRESS_PREFIX = "[vitest-file]";
3
+ export type FileProgressEvent = 'start' | 'finish';
4
+ export type WriteProgress = (chunk: string) => void;
5
+ type Clock = () => number;
6
+ export interface FileProgressReporterOptions {
7
+ write?: WriteProgress;
8
+ now?: Clock;
9
+ /** Marker prefix for each line. Defaults to `DEFAULT_FILE_PROGRESS_PREFIX`. */
10
+ prefix?: string;
11
+ }
12
+ export declare function formatFileProgress(event: FileProgressEvent, moduleId: string, state?: string, atMs?: number, prefix?: string): string;
13
+ declare class VitestFileProgressReporter implements Reporter {
14
+ private readonly write;
15
+ private readonly now;
16
+ private readonly prefix;
17
+ constructor(write: WriteProgress, now: Clock, prefix: string);
18
+ onTestModuleQueued(testModule: TestModule): void;
19
+ onTestModuleEnd(testModule: TestModule): void;
20
+ }
21
+ export declare function createFileProgressWriter(filePath: string): WriteProgress;
22
+ export declare function createVitestFileProgressReporter(options?: FileProgressReporterOptions): VitestFileProgressReporter;
23
+ export declare function isFileProgressReporter(reporter: unknown): reporter is VitestFileProgressReporter;
24
+ export {};
@@ -0,0 +1,49 @@
1
+ import { appendFileSync, writeSync } from 'node:fs';
2
+ export const DEFAULT_FILE_PROGRESS_PREFIX = '[vitest-file]';
3
+ const MAX_MODULE_ID_CHARS = 400;
4
+ function moduleId(testModule) {
5
+ return testModule.relativeModuleId || testModule.moduleId;
6
+ }
7
+ export function formatFileProgress(event, moduleId, state, atMs, prefix = DEFAULT_FILE_PROGRESS_PREFIX) {
8
+ let boundedModuleId = moduleId.slice(0, MAX_MODULE_ID_CHARS);
9
+ if (boundedModuleId.length < moduleId.length) {
10
+ boundedModuleId = `${boundedModuleId.slice(0, -1)}…`;
11
+ }
12
+ const stateToken = state !== undefined && /^[a-z]+$/u.test(state) ? ` state=${state}` : '';
13
+ // Epoch milliseconds, so a deadline report can tell a slow file from a stuck one.
14
+ const atToken = atMs !== undefined && Number.isSafeInteger(atMs) ? ` at=${atMs}` : '';
15
+ return `${prefix} event=${event} module=${JSON.stringify(boundedModuleId)}${stateToken}${atToken}\n`;
16
+ }
17
+ class VitestFileProgressReporter {
18
+ write;
19
+ now;
20
+ prefix;
21
+ constructor(write, now, prefix) {
22
+ this.write = write;
23
+ this.now = now;
24
+ this.prefix = prefix;
25
+ }
26
+ onTestModuleQueued(testModule) {
27
+ // Queued fires when a worker takes the file, before import. A shard that dies
28
+ // during that file still has this line; the CI minimal reporter prints nothing.
29
+ this.write(formatFileProgress('start', moduleId(testModule), undefined, this.now(), this.prefix));
30
+ }
31
+ onTestModuleEnd(testModule) {
32
+ this.write(formatFileProgress('finish', moduleId(testModule), testModule.state(), this.now(), this.prefix));
33
+ }
34
+ }
35
+ function writeProgressLine(chunk) {
36
+ writeSync(process.stdout.fd, chunk);
37
+ }
38
+ // Appends each event to a file so a quiet CI run keeps its start/finish history without logging it.
39
+ export function createFileProgressWriter(filePath) {
40
+ return (chunk) => {
41
+ appendFileSync(filePath, chunk);
42
+ };
43
+ }
44
+ export function createVitestFileProgressReporter(options = {}) {
45
+ return new VitestFileProgressReporter(options.write ?? writeProgressLine, options.now ?? Date.now, options.prefix ?? DEFAULT_FILE_PROGRESS_PREFIX);
46
+ }
47
+ export function isFileProgressReporter(reporter) {
48
+ return reporter instanceof VitestFileProgressReporter;
49
+ }
@@ -0,0 +1,13 @@
1
+ export interface GithubActionsEnv {
2
+ GITHUB_WORKSPACE?: string | undefined;
3
+ GITHUB_REPOSITORY?: string | undefined;
4
+ GITHUB_SHA?: string | undefined;
5
+ }
6
+ export interface NormalizeGithubActionsPathOptions {
7
+ env?: GithubActionsEnv;
8
+ cwd?: string;
9
+ }
10
+ /** Rewrites an absolute path under the workspace or cwd to a repo-relative annotation path. */
11
+ export declare function normalizeGithubActionsPath(filePath: string, options?: NormalizeGithubActionsPathOptions): string;
12
+ /** The `github-actions` reporter tuple with path normalization and job-summary links wired. */
13
+ export declare function githubActionsReporter(options?: NormalizeGithubActionsPathOptions): readonly [string, Record<string, unknown>];
@@ -0,0 +1,35 @@
1
+ import path, { relative } from 'node:path';
2
+ /** Rewrites an absolute path under the workspace or cwd to a repo-relative annotation path. */
3
+ export function normalizeGithubActionsPath(filePath, options = {}) {
4
+ const env = options.env ?? process.env;
5
+ const normalizedPath = filePath.replace(/\\/g, '/');
6
+ const roots = [env.GITHUB_WORKSPACE, options.cwd ?? process.cwd()].filter((root) => Boolean(root));
7
+ for (const root of roots) {
8
+ const normalizedRoot = root.replace(/\\/g, '/');
9
+ const relativePath = path.isAbsolute(normalizedPath)
10
+ ? relative(normalizedRoot, normalizedPath)
11
+ : normalizedPath;
12
+ if (!relativePath.startsWith('..') && !path.isAbsolute(relativePath)) {
13
+ return relativePath.replace(/\\/g, '/');
14
+ }
15
+ }
16
+ return normalizedPath;
17
+ }
18
+ /** The `github-actions` reporter tuple with path normalization and job-summary links wired. */
19
+ export function githubActionsReporter(options = {}) {
20
+ const env = options.env ?? process.env;
21
+ return [
22
+ 'github-actions',
23
+ {
24
+ onWritePath: (filePath) => normalizeGithubActionsPath(filePath, options),
25
+ jobSummary: {
26
+ enabled: false,
27
+ fileLinks: {
28
+ repository: env.GITHUB_REPOSITORY,
29
+ commitHash: env.GITHUB_SHA,
30
+ workspacePath: env.GITHUB_WORKSPACE,
31
+ },
32
+ },
33
+ },
34
+ ];
35
+ }
@@ -0,0 +1,24 @@
1
+ import type { Reporter, TestModule } from 'vitest/node';
2
+ export declare const DEFAULT_STORYBOOK_PROGRESS_PREFIX = "[vitest-browser-progress]";
3
+ export type StorybookProgressEvent = 'module-collected' | 'module-start' | 'module-end';
4
+ type WriteProgress = (chunk: string) => void;
5
+ export interface StorybookProgressReporterOptions {
6
+ write?: WriteProgress;
7
+ /** Marker prefix for each line. Defaults to `DEFAULT_STORYBOOK_PROGRESS_PREFIX`. */
8
+ prefix?: string;
9
+ }
10
+ declare class VitestStorybookProgressReporter implements Reporter {
11
+ private sequence;
12
+ private readonly write;
13
+ private readonly prefix;
14
+ constructor(write: WriteProgress, prefix: string);
15
+ onTestRunStart(): void;
16
+ onTestModuleCollected(testModule: TestModule): void;
17
+ onTestModuleStart(testModule: TestModule): void;
18
+ onTestModuleEnd(testModule: TestModule): void;
19
+ private emit;
20
+ }
21
+ export declare function createVitestStorybookProgressReporter(options?: StorybookProgressReporterOptions): VitestStorybookProgressReporter;
22
+ export declare function formatStorybookProgressMarker(sequence: number, event: StorybookProgressEvent, moduleId: string, prefix?: string): string;
23
+ export declare function latestStorybookProgressSequence(text: string, prefix?: string): number | null;
24
+ export {};
@@ -0,0 +1,53 @@
1
+ export const DEFAULT_STORYBOOK_PROGRESS_PREFIX = '[vitest-browser-progress]';
2
+ const MAX_MARKER_BYTES = 512;
3
+ const MAX_MODULE_ID_CHARS = 400;
4
+ class VitestStorybookProgressReporter {
5
+ sequence = 0;
6
+ write;
7
+ prefix;
8
+ constructor(write, prefix) {
9
+ this.write = write;
10
+ this.prefix = prefix;
11
+ }
12
+ onTestRunStart() {
13
+ this.sequence = 0;
14
+ }
15
+ onTestModuleCollected(testModule) {
16
+ this.emit('module-collected', testModule);
17
+ }
18
+ onTestModuleStart(testModule) {
19
+ this.emit('module-start', testModule);
20
+ }
21
+ onTestModuleEnd(testModule) {
22
+ this.emit('module-end', testModule);
23
+ }
24
+ emit(event, testModule) {
25
+ this.sequence += 1;
26
+ this.write(formatStorybookProgressMarker(this.sequence, event, testModule.relativeModuleId || testModule.moduleId, this.prefix));
27
+ }
28
+ }
29
+ export function createVitestStorybookProgressReporter(options = {}) {
30
+ return new VitestStorybookProgressReporter(options.write ?? ((chunk) => process.stdout.write(chunk)), options.prefix ?? DEFAULT_STORYBOOK_PROGRESS_PREFIX);
31
+ }
32
+ export function formatStorybookProgressMarker(sequence, event, moduleId, prefix = DEFAULT_STORYBOOK_PROGRESS_PREFIX) {
33
+ let boundedModuleId = moduleId.slice(0, MAX_MODULE_ID_CHARS);
34
+ while (boundedModuleId.length > 0) {
35
+ const suffix = boundedModuleId.length < moduleId.length ? '…' : '';
36
+ const marker = `${prefix} seq=${sequence} event=${event} module=${JSON.stringify(`${boundedModuleId}${suffix}`)}\n`;
37
+ if (Buffer.byteLength(marker) <= MAX_MARKER_BYTES)
38
+ return marker;
39
+ boundedModuleId = boundedModuleId.slice(0, -16);
40
+ }
41
+ return `${prefix} seq=${sequence} event=${event} module=""\n`;
42
+ }
43
+ export function latestStorybookProgressSequence(text, prefix = DEFAULT_STORYBOOK_PROGRESS_PREFIX) {
44
+ const escaped = prefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
45
+ const pattern = new RegExp(`${escaped} seq=(\\d+) event=module-(?:collected|start|end)\\b`, 'g');
46
+ let latest = null;
47
+ for (const match of text.matchAll(pattern)) {
48
+ const sequence = Number(match[1]);
49
+ if (Number.isSafeInteger(sequence))
50
+ latest = Math.max(latest ?? 0, sequence);
51
+ }
52
+ return latest;
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vouchington-tooling",
3
- "version": "0.61.0",
3
+ "version": "0.62.0",
4
4
  "description": "Vouchington CLI and extractable tooling libraries.",
5
5
  "homepage": "https://github.com/vouchington/vouchington-tooling/tree/main/packages/vouchington-tooling#readme",
6
6
  "bugs": {
@@ -1,8 +0,0 @@
1
- export type HookPayload = Record<string, unknown>;
2
- /** Tool name across Claude-compatible (`tool_name`), camelCase and bare (`name`) payloads. */
3
- export declare function hookToolName(payload: HookPayload): string;
4
- /** The shell command a tool call ran, or '' when the payload carries none. */
5
- export declare function extractToolCommand(payload: HookPayload): string;
6
- /** A numeric `exit_code` from the response shapes that carry one; undefined otherwise. */
7
- export declare function toolExitCode(payload: HookPayload): number | undefined;
8
- export declare function parseHookPayload(raw: string): HookPayload;
@@ -1,39 +0,0 @@
1
- function isRecord(value) {
2
- return typeof value === 'object' && value !== null && !Array.isArray(value);
3
- }
4
- /** Tool name across Claude-compatible (`tool_name`), camelCase and bare (`name`) payloads. */
5
- export function hookToolName(payload) {
6
- for (const key of ['tool_name', 'toolName', 'name']) {
7
- const value = payload[key];
8
- if (typeof value === 'string')
9
- return value;
10
- }
11
- return '';
12
- }
13
- /** The shell command a tool call ran, or '' when the payload carries none. */
14
- export function extractToolCommand(payload) {
15
- for (const key of ['tool_input', 'toolInput', 'input']) {
16
- const input = payload[key];
17
- if (isRecord(input) && typeof input.command === 'string')
18
- return input.command;
19
- }
20
- return typeof payload.command === 'string' ? payload.command : '';
21
- }
22
- /** A numeric `exit_code` from the response shapes that carry one; undefined otherwise. */
23
- export function toolExitCode(payload) {
24
- for (const key of ['tool_response', 'toolResponse', 'toolResult']) {
25
- const response = payload[key];
26
- if (isRecord(response) && typeof response.exit_code === 'number')
27
- return response.exit_code;
28
- }
29
- return undefined;
30
- }
31
- export function parseHookPayload(raw) {
32
- try {
33
- const parsed = JSON.parse(raw);
34
- return isRecord(parsed) ? parsed : {};
35
- }
36
- catch {
37
- return {};
38
- }
39
- }