@blinkhost/cli 2.7.0 → 2.8.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/CHANGELOG.md +4 -0
- package/README.md +514 -2
- package/dist/api.d.ts +2 -2
- package/dist/api.js +57 -8
- package/dist/assistant.js +6 -1
- package/dist/cli.js +157 -9
- package/dist/guidance.d.ts +1 -1
- package/dist/guidance.js +43 -11
- package/dist/javascript-runtime/resource-limits.js +3 -0
- package/dist/javascript-runtime/resource-profiles.js +2 -0
- package/dist/local-dev.d.ts +3 -0
- package/dist/local-dev.js +145 -0
- package/dist/local-development/README.md +410 -0
- package/dist/local-development/artifact-watch.mjs +36 -0
- package/dist/local-development/blinkhost.local.example.json +15 -0
- package/dist/local-development/frontend-proxy.mjs +189 -0
- package/dist/local-development/hello.rs +24 -0
- package/dist/local-development/local-stack.mjs +511 -0
- package/dist/local-development/native-database.mjs +37 -0
- package/dist/local-development/provider-fixtures.example.json +36 -0
- package/dist/local-development/provider-fixtures.mjs +203 -0
- package/dist/local-development/provider-grants.mjs +36 -0
- package/dist/local-development/test-provider-example.mjs +74 -0
- package/dist/local-source-build.d.ts +39 -0
- package/dist/local-source-build.js +225 -0
- package/dist/local-source-watch.d.ts +24 -0
- package/dist/local-source-watch.js +87 -0
- package/dist/local-test-command.d.ts +49 -0
- package/dist/local-test-command.js +128 -0
- package/dist/local-test-config.d.ts +37 -0
- package/dist/local-test-config.js +174 -0
- package/dist/local-test-gates.d.ts +71 -0
- package/dist/local-test-gates.js +247 -0
- package/dist/local-test-go-runner.d.ts +27 -0
- package/dist/local-test-go-runner.js +209 -0
- package/dist/local-test-node-arguments.d.ts +2 -0
- package/dist/local-test-node-arguments.js +14 -0
- package/dist/local-test-node-reporter.d.ts +7 -0
- package/dist/local-test-node-reporter.js +159 -0
- package/dist/local-test-results.d.ts +65 -0
- package/dist/local-test-results.js +163 -0
- package/dist/local-test-rust-runner.d.ts +18 -0
- package/dist/local-test-rust-runner.js +252 -0
- package/dist/local-test-starters.d.ts +3 -0
- package/dist/local-test-starters.js +157 -0
- package/dist/logs.d.ts +43 -0
- package/dist/logs.js +417 -0
- package/dist/module-build-diagnostics.d.ts +10 -0
- package/dist/module-build-diagnostics.js +208 -0
- package/dist/module-build.js +4 -0
- package/dist/release-preparation-diagnostics.d.ts +38 -0
- package/dist/release-preparation-diagnostics.js +204 -0
- package/dist/remote.js +14 -0
- package/dist/templates.d.ts +1 -0
- package/dist/templates.js +4 -1
- package/dist/test-credentials.d.ts +7 -0
- package/dist/test-credentials.js +236 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workflows.d.ts +39 -2
- package/dist/workflows.js +241 -14
- package/package.json +4 -3
- package/test-runners/python-unittest.py +266 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
|
+
import { CliError } from './errors.js';
|
|
5
|
+
import { buildLocalSource, fingerprintLocalSource, localSourceFingerprint } from './local-source-build.js';
|
|
6
|
+
const errorCode = (error) => error instanceof CliError ? error.code
|
|
7
|
+
: error instanceof Error && /^[a-z_]{1,96}$/.test(error.message) ? error.message : 'local_source_rebuild_failed';
|
|
8
|
+
/** Serial, bounded rebuilds. No overlapping compilers or inferred source/configuration discovery. */
|
|
9
|
+
export async function watchLocalSource(root, filename, directory, initial, publish, runtimeAvailable, onEvent, { signal, pollMs = 1000, maxBuilds = 32, maxEvents = 64 }) {
|
|
10
|
+
if (!Number.isSafeInteger(pollMs) || pollMs < 1 || pollMs > 5000
|
|
11
|
+
|| !Number.isSafeInteger(maxBuilds) || maxBuilds < 1 || maxBuilds > 32
|
|
12
|
+
|| !Number.isSafeInteger(maxEvents) || maxEvents < 1 || maxEvents > 64)
|
|
13
|
+
throw new Error('invalid_local_source_watch_limits');
|
|
14
|
+
let seen = localSourceFingerprint(initial.source_sha256), attempt = 0, events = 0;
|
|
15
|
+
const emit = async (event) => {
|
|
16
|
+
if (signal.aborted)
|
|
17
|
+
return;
|
|
18
|
+
await writeFile(join(directory, `source-rebuild-${String(++events).padStart(3, '0')}.json`), JSON.stringify(event, null, 2) + '\n', { flag: 'wx', mode: 0o600 });
|
|
19
|
+
if (!signal.aborted)
|
|
20
|
+
await onEvent(event);
|
|
21
|
+
};
|
|
22
|
+
while (!signal.aborted) {
|
|
23
|
+
try {
|
|
24
|
+
await delay(pollMs, undefined, { signal });
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (signal.aborted)
|
|
28
|
+
return;
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
if (signal.aborted)
|
|
32
|
+
return;
|
|
33
|
+
let fingerprint;
|
|
34
|
+
try {
|
|
35
|
+
fingerprint = await fingerprintLocalSource(root, filename, initial, signal);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (signal.aborted)
|
|
39
|
+
return;
|
|
40
|
+
const code = errorCode(error);
|
|
41
|
+
if (seen === 'error:' + code)
|
|
42
|
+
continue;
|
|
43
|
+
seen = 'error:' + code;
|
|
44
|
+
const exhausted = events >= maxEvents;
|
|
45
|
+
await emit({ schema: 'blinkhost.local-source-rebuild/v1', status: 'rejected', attempt,
|
|
46
|
+
error: exhausted ? 'local_source_watch_event_limit' : code, previous_runtime_retained: runtimeAvailable(),
|
|
47
|
+
...(exhausted ? { watching_stopped: true } : {}), production_authority: false });
|
|
48
|
+
if (exhausted)
|
|
49
|
+
return;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (fingerprint === seen)
|
|
53
|
+
continue;
|
|
54
|
+
seen = fingerprint;
|
|
55
|
+
if (attempt >= maxBuilds || events >= maxEvents) {
|
|
56
|
+
await emit({ schema: 'blinkhost.local-source-rebuild/v1', status: 'rejected', attempt,
|
|
57
|
+
error: attempt >= maxBuilds ? 'local_source_watch_build_limit' : 'local_source_watch_event_limit',
|
|
58
|
+
previous_runtime_retained: runtimeAvailable(), watching_stopped: true, production_authority: false });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
let build, event;
|
|
62
|
+
try {
|
|
63
|
+
build = await buildLocalSource(root, filename, join(directory, `build-${String(++attempt + 1).padStart(3, '0')}`), { signal });
|
|
64
|
+
if (signal.aborted)
|
|
65
|
+
return;
|
|
66
|
+
const expected = localSourceFingerprint(build.source_sha256);
|
|
67
|
+
const verifyCandidate = async () => {
|
|
68
|
+
if (signal.aborted)
|
|
69
|
+
throw new Error('local_source_build_cancelled');
|
|
70
|
+
if (await fingerprintLocalSource(root, filename, initial, signal) !== expected)
|
|
71
|
+
throw new Error('local_source_build_source_changed');
|
|
72
|
+
};
|
|
73
|
+
await verifyCandidate();
|
|
74
|
+
const reload = await publish(build, verifyCandidate);
|
|
75
|
+
event = { schema: 'blinkhost.local-source-rebuild/v1', status: reload.status, attempt, build, reload,
|
|
76
|
+
...(reload.error ? { error: reload.error } : {}), previous_runtime_retained: reload.status !== 'reloaded' && runtimeAvailable(), production_authority: false };
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (signal.aborted)
|
|
80
|
+
return;
|
|
81
|
+
event = { schema: 'blinkhost.local-source-rebuild/v1', status: 'rejected', attempt, error: errorCode(error),
|
|
82
|
+
...(build ? { build } : {}), previous_runtime_retained: runtimeAvailable(), production_authority: false };
|
|
83
|
+
}
|
|
84
|
+
await emit(event);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=local-source-watch.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CliError } from './errors.js';
|
|
2
|
+
export declare const LOCAL_TEST_LIMITS: {
|
|
3
|
+
readonly timeoutMs: 900000;
|
|
4
|
+
readonly maxTimeoutMs: 3600000;
|
|
5
|
+
readonly maxOutputBytes: number;
|
|
6
|
+
readonly maximumOutputBytes: number;
|
|
7
|
+
readonly terminationGraceMs: 1000;
|
|
8
|
+
};
|
|
9
|
+
export interface LocalTestCommandResult {
|
|
10
|
+
status: 'succeeded' | 'failed' | 'timed_out' | 'cancelled' | 'output_limit' | 'unavailable';
|
|
11
|
+
exit_code: number | null;
|
|
12
|
+
signal: NodeJS.Signals | null;
|
|
13
|
+
duration_ms: number;
|
|
14
|
+
observed_output_bytes: number;
|
|
15
|
+
captured_output_bytes: number;
|
|
16
|
+
output: {
|
|
17
|
+
stdout: string;
|
|
18
|
+
stderr: string;
|
|
19
|
+
sanitization: 'common_credentials_and_terminal_controls';
|
|
20
|
+
};
|
|
21
|
+
limits: {
|
|
22
|
+
timeout_ms: number;
|
|
23
|
+
max_output_bytes: number;
|
|
24
|
+
termination_grace_ms: number;
|
|
25
|
+
};
|
|
26
|
+
cleanup: {
|
|
27
|
+
scope: 'posix_process_group' | 'direct_child';
|
|
28
|
+
kill_requested: boolean;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export declare class LocalTestChecksFailure extends CliError {
|
|
32
|
+
readonly projectChecks?: unknown | undefined;
|
|
33
|
+
constructor(message: string, exitCode: number, code: string, details?: string[], projectChecks?: unknown | undefined);
|
|
34
|
+
}
|
|
35
|
+
export declare class LocalTestCommandFailure extends LocalTestChecksFailure {
|
|
36
|
+
readonly execution: LocalTestCommandResult;
|
|
37
|
+
constructor(message: string, exitCode: number, code: string, execution: LocalTestCommandResult, details?: string[], projectChecks?: unknown);
|
|
38
|
+
}
|
|
39
|
+
/** Heuristic screening of local diagnostics, not a guarantee that output is secret-free. */
|
|
40
|
+
export declare function sanitizeLocalTestOutput(value: string): string;
|
|
41
|
+
/** Local customer commands only. Process groups are cleanup scope, not a security sandbox. */
|
|
42
|
+
export declare function runLocalTestCommand(command: string, args: string[], options: {
|
|
43
|
+
cwd: string;
|
|
44
|
+
env?: NodeJS.ProcessEnv;
|
|
45
|
+
timeoutMs?: number;
|
|
46
|
+
maxOutputBytes?: number;
|
|
47
|
+
terminationGraceMs?: number;
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
}): Promise<LocalTestCommandResult>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { CliError, EXIT } from './errors.js';
|
|
3
|
+
export const LOCAL_TEST_LIMITS = {
|
|
4
|
+
timeoutMs: 900_000, maxTimeoutMs: 3_600_000,
|
|
5
|
+
maxOutputBytes: 1024 * 1024, maximumOutputBytes: 8 * 1024 * 1024,
|
|
6
|
+
terminationGraceMs: 1000,
|
|
7
|
+
};
|
|
8
|
+
export class LocalTestChecksFailure extends CliError {
|
|
9
|
+
projectChecks;
|
|
10
|
+
constructor(message, exitCode, code, details = [], projectChecks) {
|
|
11
|
+
super(message, exitCode, code, details);
|
|
12
|
+
this.projectChecks = projectChecks;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class LocalTestCommandFailure extends LocalTestChecksFailure {
|
|
16
|
+
execution;
|
|
17
|
+
constructor(message, exitCode, code, execution, details = [], projectChecks) {
|
|
18
|
+
super(message, exitCode, code, details, projectChecks);
|
|
19
|
+
this.execution = execution;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Heuristic screening of local diagnostics, not a guarantee that output is secret-free. */
|
|
23
|
+
export function sanitizeLocalTestOutput(value) {
|
|
24
|
+
return value
|
|
25
|
+
.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, '')
|
|
26
|
+
.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g, '')
|
|
27
|
+
.replace(/-----BEGIN ([A-Z ]*PRIVATE KEY)-----[\s\S]*?(?:-----END \1-----|$)/g, '[REDACTED PRIVATE KEY]')
|
|
28
|
+
.replace(/\b(Bearer|Basic)\s+[^\s"'<>]+/gi, '$1 [REDACTED]')
|
|
29
|
+
.replace(/(["']?(?:authorization|password|passwd|secret|token|api[_-]?key|access[_-]?token|refresh[_-]?token)["']?\s*[:=]\s*)(?:"[^"\n]*"|'[^'\n]*'|[^\s,;}]+)/gi, '$1[REDACTED]')
|
|
30
|
+
.replace(/(https?:\/\/)[^\s/@]+:[^\s/@]+@/gi, '$1[REDACTED]@');
|
|
31
|
+
}
|
|
32
|
+
/** Local customer commands only. Process groups are cleanup scope, not a security sandbox. */
|
|
33
|
+
export async function runLocalTestCommand(command, args, options) {
|
|
34
|
+
const timeoutMs = options.timeoutMs ?? LOCAL_TEST_LIMITS.timeoutMs;
|
|
35
|
+
const maxOutputBytes = options.maxOutputBytes ?? LOCAL_TEST_LIMITS.maxOutputBytes;
|
|
36
|
+
const graceMs = options.terminationGraceMs ?? LOCAL_TEST_LIMITS.terminationGraceMs;
|
|
37
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > LOCAL_TEST_LIMITS.maxTimeoutMs
|
|
38
|
+
|| !Number.isSafeInteger(maxOutputBytes) || maxOutputBytes < 1 || maxOutputBytes > LOCAL_TEST_LIMITS.maximumOutputBytes
|
|
39
|
+
|| !Number.isSafeInteger(graceMs) || graceMs < 0 || graceMs > 5000) {
|
|
40
|
+
throw new CliError('Invalid local test execution limits.', EXIT.usage, 'invalid_test_limits');
|
|
41
|
+
}
|
|
42
|
+
const group = process.platform !== 'win32';
|
|
43
|
+
const started = performance.now();
|
|
44
|
+
const stdout = [];
|
|
45
|
+
const stderr = [];
|
|
46
|
+
let bytes = 0;
|
|
47
|
+
let captured = 0;
|
|
48
|
+
let killRequested = false;
|
|
49
|
+
const receipt = (status, code, signal) => ({
|
|
50
|
+
status, exit_code: code, signal, duration_ms: Math.round(performance.now() - started),
|
|
51
|
+
observed_output_bytes: bytes, captured_output_bytes: captured,
|
|
52
|
+
output: { stdout: sanitizeLocalTestOutput(Buffer.concat(stdout).toString('utf8')),
|
|
53
|
+
stderr: sanitizeLocalTestOutput(Buffer.concat(stderr).toString('utf8')),
|
|
54
|
+
sanitization: 'common_credentials_and_terminal_controls' },
|
|
55
|
+
limits: { timeout_ms: timeoutMs, max_output_bytes: maxOutputBytes, termination_grace_ms: graceMs },
|
|
56
|
+
cleanup: { scope: group ? 'posix_process_group' : 'direct_child', kill_requested: killRequested },
|
|
57
|
+
});
|
|
58
|
+
if (options.signal?.aborted)
|
|
59
|
+
return receipt('cancelled', null, null);
|
|
60
|
+
return new Promise(resolve => {
|
|
61
|
+
const child = spawn(command, args, { cwd: options.cwd, env: options.env ?? process.env,
|
|
62
|
+
shell: false, detached: group, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
|
|
63
|
+
let finished = false;
|
|
64
|
+
let termination;
|
|
65
|
+
let escalation;
|
|
66
|
+
let timeout;
|
|
67
|
+
const kill = (signal) => {
|
|
68
|
+
if (!child.pid)
|
|
69
|
+
return;
|
|
70
|
+
try {
|
|
71
|
+
if (group)
|
|
72
|
+
process.kill(-child.pid, signal);
|
|
73
|
+
else
|
|
74
|
+
child.kill(signal);
|
|
75
|
+
if (signal === 'SIGKILL')
|
|
76
|
+
killRequested = true;
|
|
77
|
+
}
|
|
78
|
+
catch { /* ESRCH means this owned process/group already exited. */ }
|
|
79
|
+
};
|
|
80
|
+
const finish = (code, signal) => {
|
|
81
|
+
if (finished)
|
|
82
|
+
return;
|
|
83
|
+
finished = true;
|
|
84
|
+
clearTimeout(timeout);
|
|
85
|
+
clearTimeout(escalation);
|
|
86
|
+
options.signal?.removeEventListener('abort', abort);
|
|
87
|
+
// Clean up descendants that outlived a successful root test process, too.
|
|
88
|
+
kill('SIGKILL');
|
|
89
|
+
child.stdout.destroy();
|
|
90
|
+
child.stderr.destroy();
|
|
91
|
+
resolve(receipt(termination ?? (code === 0 ? 'succeeded' : 'failed'), code, signal));
|
|
92
|
+
};
|
|
93
|
+
const stop = (reason) => {
|
|
94
|
+
if (finished || termination)
|
|
95
|
+
return;
|
|
96
|
+
termination = reason;
|
|
97
|
+
kill('SIGTERM');
|
|
98
|
+
escalation = setTimeout(() => {
|
|
99
|
+
kill('SIGKILL');
|
|
100
|
+
// Bound inherited pipes even when a child escapes the owned process group.
|
|
101
|
+
finish(child.exitCode, child.signalCode);
|
|
102
|
+
}, graceMs);
|
|
103
|
+
};
|
|
104
|
+
const abort = () => stop('cancelled');
|
|
105
|
+
const collect = (chunk, output) => {
|
|
106
|
+
if (finished || termination)
|
|
107
|
+
return;
|
|
108
|
+
bytes += chunk.length;
|
|
109
|
+
const remaining = maxOutputBytes - captured;
|
|
110
|
+
if (chunk.length <= remaining) {
|
|
111
|
+
output.push(chunk);
|
|
112
|
+
captured += chunk.length;
|
|
113
|
+
}
|
|
114
|
+
// Drop the overflowing chunk whole; do not expose a partially cut credential.
|
|
115
|
+
else
|
|
116
|
+
stop('output_limit');
|
|
117
|
+
};
|
|
118
|
+
child.stdout.on('data', (chunk) => collect(chunk, stdout));
|
|
119
|
+
child.stderr.on('data', (chunk) => collect(chunk, stderr));
|
|
120
|
+
child.once('error', () => { termination ??= 'unavailable'; finish(null, null); });
|
|
121
|
+
child.once('close', finish);
|
|
122
|
+
options.signal?.addEventListener('abort', abort, { once: true });
|
|
123
|
+
timeout = setTimeout(() => stop('timed_out'), timeoutMs);
|
|
124
|
+
if (options.signal?.aborted)
|
|
125
|
+
abort();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=local-test-command.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type BlinkHostManifest } from './manifest.js';
|
|
2
|
+
export declare const LOCAL_TEST_CONFIG = "blinkhost.tests.json";
|
|
3
|
+
export declare const TEST_DISCOVERY_LIMITS: {
|
|
4
|
+
readonly directories: 2048;
|
|
5
|
+
readonly entries: 16384;
|
|
6
|
+
readonly depth: 8;
|
|
7
|
+
readonly projects: 128;
|
|
8
|
+
};
|
|
9
|
+
export interface LocalCheckDefinition {
|
|
10
|
+
id: string;
|
|
11
|
+
target: string;
|
|
12
|
+
cwd: string;
|
|
13
|
+
command: string;
|
|
14
|
+
args: string[];
|
|
15
|
+
kind: 'test' | 'integration' | 'build';
|
|
16
|
+
profile: 'native' | 'wasm' | 'browser' | 'unspecified';
|
|
17
|
+
results?: {
|
|
18
|
+
format: 'blinkhost/v1';
|
|
19
|
+
};
|
|
20
|
+
runner?: 'node' | 'python-unittest' | 'go' | 'rust';
|
|
21
|
+
}
|
|
22
|
+
/** Customer-selected paths stay inside the project and cannot traverse existing symlinks. */
|
|
23
|
+
export declare function localCheckDirectory(root: string, value: unknown): Promise<string>;
|
|
24
|
+
export declare function readLocalTestConfig(root: string, manifest: BlinkHostManifest): Promise<LocalCheckDefinition[] | null>;
|
|
25
|
+
export interface LocalProjectDiscovery {
|
|
26
|
+
nested_projects: Array<{
|
|
27
|
+
path: string;
|
|
28
|
+
status: 'not_run';
|
|
29
|
+
reason: 'run_explicitly' | 'unsafe_manifest';
|
|
30
|
+
}>;
|
|
31
|
+
complete: boolean;
|
|
32
|
+
directories_scanned: number;
|
|
33
|
+
entries_scanned: number;
|
|
34
|
+
limits: typeof TEST_DISCOVERY_LIMITS;
|
|
35
|
+
}
|
|
36
|
+
/** Discover only project manifests, never install dependencies or execute discovered projects. */
|
|
37
|
+
export declare function discoverLocalProjects(root: string, signal?: AbortSignal): Promise<LocalProjectDiscovery>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { lstat, open, opendir } from 'node:fs/promises';
|
|
3
|
+
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { CliError, EXIT } from './errors.js';
|
|
6
|
+
import { MANIFEST_FILENAME } from './manifest.js';
|
|
7
|
+
import { validateNodeTestArguments } from './local-test-node-arguments.js';
|
|
8
|
+
export const LOCAL_TEST_CONFIG = 'blinkhost.tests.json';
|
|
9
|
+
export const TEST_DISCOVERY_LIMITS = { directories: 2048, entries: 16_384, depth: 8, projects: 128 };
|
|
10
|
+
const OMIT = new Set(['node_modules', '.git', '.next', 'target', 'dist', 'build', 'coverage', '.cache', '.venv', 'venv', '__pycache__', 'vendor']);
|
|
11
|
+
function installedRunner(runner, args) {
|
|
12
|
+
const installed = (path) => fileURLToPath(new URL(path, import.meta.url));
|
|
13
|
+
if (runner === 'python-unittest')
|
|
14
|
+
return { command: 'python3', args: ['-B', installed('../test-runners/python-unittest.py'), ...args] };
|
|
15
|
+
if (runner === 'node') {
|
|
16
|
+
validateNodeTestArguments(args);
|
|
17
|
+
return { command: process.execPath, args: ['--test', `--test-reporter=${installed('./local-test-node-reporter.js')}`, ...args] };
|
|
18
|
+
}
|
|
19
|
+
return { command: process.execPath, args: [installed(`./local-test-${runner}-runner.js`), ...args] };
|
|
20
|
+
}
|
|
21
|
+
function invalid(message) {
|
|
22
|
+
throw new CliError(message, EXIT.validation, 'invalid_local_test_config');
|
|
23
|
+
}
|
|
24
|
+
function object(value, fields, name) {
|
|
25
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
26
|
+
invalid(`${name} must be an object.`);
|
|
27
|
+
const row = value;
|
|
28
|
+
if (Object.keys(row).some(key => !fields.includes(key)))
|
|
29
|
+
invalid(`${name} contains an unsupported field.`);
|
|
30
|
+
return row;
|
|
31
|
+
}
|
|
32
|
+
/** Customer-selected paths stay inside the project and cannot traverse existing symlinks. */
|
|
33
|
+
export async function localCheckDirectory(root, value) {
|
|
34
|
+
if (typeof value !== 'string' || !value || value.length > 1024
|
|
35
|
+
|| /[\u0000-\u001f\u007f\\]/.test(value) || isAbsolute(value))
|
|
36
|
+
invalid('Check cwd must be a relative project directory.');
|
|
37
|
+
const target = resolve(root, value);
|
|
38
|
+
const offset = relative(root, target);
|
|
39
|
+
if (offset === '..' || /^\.\.[\\/]/.test(offset) || isAbsolute(offset))
|
|
40
|
+
invalid('Check cwd escapes the project.');
|
|
41
|
+
let cursor = root;
|
|
42
|
+
for (const part of offset.split(/[\\/]/).filter(Boolean)) {
|
|
43
|
+
cursor = join(cursor, part);
|
|
44
|
+
const stat = await lstat(cursor);
|
|
45
|
+
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
46
|
+
invalid('Check cwd must use regular project directories.');
|
|
47
|
+
}
|
|
48
|
+
return offset.replaceAll('\\', '/') || '.';
|
|
49
|
+
}
|
|
50
|
+
export async function readLocalTestConfig(root, manifest) {
|
|
51
|
+
const path = join(root, LOCAL_TEST_CONFIG);
|
|
52
|
+
let file;
|
|
53
|
+
try {
|
|
54
|
+
const stat = await lstat(path);
|
|
55
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
56
|
+
invalid(`${LOCAL_TEST_CONFIG} must be a regular file.`);
|
|
57
|
+
file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error.code === 'ENOENT')
|
|
61
|
+
return null;
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
let source;
|
|
65
|
+
try {
|
|
66
|
+
const stat = await file.stat();
|
|
67
|
+
if (!stat.isFile() || stat.size > 65_536)
|
|
68
|
+
invalid(`${LOCAL_TEST_CONFIG} exceeds the 64 KiB limit.`);
|
|
69
|
+
// Bound the read even if a local editor grows the file after fstat.
|
|
70
|
+
const buffer = Buffer.alloc(65_537);
|
|
71
|
+
const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
|
|
72
|
+
if (bytesRead > 65_536)
|
|
73
|
+
invalid(`${LOCAL_TEST_CONFIG} exceeds the 64 KiB limit.`);
|
|
74
|
+
source = buffer.subarray(0, bytesRead);
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
await file.close();
|
|
78
|
+
}
|
|
79
|
+
let parsed;
|
|
80
|
+
try {
|
|
81
|
+
parsed = JSON.parse(source.toString('utf8'));
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
invalid(`${LOCAL_TEST_CONFIG} must contain valid JSON.`);
|
|
85
|
+
}
|
|
86
|
+
const config = object(parsed, ['schema', 'checks'], LOCAL_TEST_CONFIG);
|
|
87
|
+
if (config.schema !== 'blinkhost.local-test-config/v1')
|
|
88
|
+
invalid('Unsupported local test configuration schema.');
|
|
89
|
+
if (!Array.isArray(config.checks) || config.checks.length < 1 || config.checks.length > 32)
|
|
90
|
+
invalid('Configure between one and 32 local checks.');
|
|
91
|
+
const ids = new Set();
|
|
92
|
+
const results = [];
|
|
93
|
+
for (const value of config.checks) {
|
|
94
|
+
const row = object(value, ['id', 'target', 'cwd', 'command', 'runner', 'args', 'kind', 'profile', 'results'], 'Check');
|
|
95
|
+
if (typeof row.id !== 'string' || !/^[a-z0-9][a-z0-9_-]{0,63}$/.test(row.id) || ids.has(row.id))
|
|
96
|
+
invalid('Check IDs must be unique safe names.');
|
|
97
|
+
ids.add(row.id);
|
|
98
|
+
const module = manifest.modules.find(item => row.target === `module:${item.name}`);
|
|
99
|
+
if (row.target !== 'frontend' && row.target !== 'project' && !module)
|
|
100
|
+
invalid('Check target must name frontend, project or a declared module:<name>.');
|
|
101
|
+
const runner = row.runner;
|
|
102
|
+
if (row.runner !== undefined) {
|
|
103
|
+
if (typeof row.runner !== 'string' || !['node', 'python-unittest', 'go', 'rust'].includes(row.runner) || row.command !== undefined)
|
|
104
|
+
invalid('Choose one installed runner or a custom command.');
|
|
105
|
+
}
|
|
106
|
+
else if (typeof row.command !== 'string' || !row.command || row.command.length > 1024 || /[\u0000-\u001f\u007f]/.test(row.command))
|
|
107
|
+
invalid('Check command must be a bounded executable name or path.');
|
|
108
|
+
const args = row.args ?? [];
|
|
109
|
+
if (!Array.isArray(args) || args.length > 64 || args.some(arg => typeof arg !== 'string' || arg.length > 4096 || /[\u0000-\u001f\u007f]/.test(arg))
|
|
110
|
+
|| args.reduce((sum, arg) => sum + Buffer.byteLength(arg), 0) > 32_768)
|
|
111
|
+
invalid('Check args must be bounded literal strings.');
|
|
112
|
+
if (!['test', 'integration', 'build'].includes(String(row.kind)))
|
|
113
|
+
invalid('Check kind must be test, integration or build.');
|
|
114
|
+
const profile = row.profile ?? 'unspecified';
|
|
115
|
+
if (!['native', 'wasm', 'browser', 'unspecified'].includes(String(profile)))
|
|
116
|
+
invalid('Unsupported declared check profile.');
|
|
117
|
+
if (runner && (profile !== 'native' || row.kind !== 'test'))
|
|
118
|
+
invalid('Installed runners require kind test and profile native.');
|
|
119
|
+
if (row.results !== undefined) {
|
|
120
|
+
const report = object(row.results, ['format'], 'Check results');
|
|
121
|
+
if (report.format !== 'blinkhost/v1' || row.kind === 'build')
|
|
122
|
+
invalid('Structured results require a test/integration check and blinkhost/v1 format.');
|
|
123
|
+
}
|
|
124
|
+
const cwd = await localCheckDirectory(root, row.cwd ?? module?.path ?? (row.target === 'frontend' ? manifest.frontend.dependency_root : '.'));
|
|
125
|
+
const execution = runner ? installedRunner(runner, args) : { command: row.command, args: args };
|
|
126
|
+
results.push({ id: row.id, target: row.target, cwd, ...execution,
|
|
127
|
+
kind: row.kind, profile: profile,
|
|
128
|
+
...(runner ? { runner } : {}),
|
|
129
|
+
...(runner || row.results !== undefined ? { results: { format: 'blinkhost/v1' } } : {}) });
|
|
130
|
+
}
|
|
131
|
+
return results;
|
|
132
|
+
}
|
|
133
|
+
/** Discover only project manifests, never install dependencies or execute discovered projects. */
|
|
134
|
+
export async function discoverLocalProjects(root, signal) {
|
|
135
|
+
const result = { nested_projects: [], complete: true, directories_scanned: 0,
|
|
136
|
+
entries_scanned: 0, limits: TEST_DISCOVERY_LIMITS };
|
|
137
|
+
const pending = [{ path: '.', depth: 0 }];
|
|
138
|
+
for (let index = 0; index < pending.length; index++) {
|
|
139
|
+
if (signal?.aborted)
|
|
140
|
+
throw new CliError('Project discovery was cancelled.', signal.reason === 'SIGTERM' ? 143 : 130, 'project_test_cancelled');
|
|
141
|
+
if (result.directories_scanned >= TEST_DISCOVERY_LIMITS.directories) {
|
|
142
|
+
result.complete = false;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
const current = pending[index];
|
|
146
|
+
const directory = await opendir(join(root, current.path));
|
|
147
|
+
result.directories_scanned++;
|
|
148
|
+
for await (const entry of directory) {
|
|
149
|
+
if (result.entries_scanned === TEST_DISCOVERY_LIMITS.entries) {
|
|
150
|
+
result.complete = false;
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
result.entries_scanned++;
|
|
154
|
+
if (current.depth && entry.name === MANIFEST_FILENAME) {
|
|
155
|
+
if (result.nested_projects.length === TEST_DISCOVERY_LIMITS.projects) {
|
|
156
|
+
result.complete = false;
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
result.nested_projects.push({ path: current.path, status: 'not_run', reason: entry.isFile() ? 'run_explicitly' : 'unsafe_manifest' });
|
|
160
|
+
}
|
|
161
|
+
if (!entry.isDirectory() || OMIT.has(entry.name))
|
|
162
|
+
continue;
|
|
163
|
+
if (current.depth === TEST_DISCOVERY_LIMITS.depth || pending.length === TEST_DISCOVERY_LIMITS.directories) {
|
|
164
|
+
result.complete = false;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const path = current.path === '.' ? entry.name : `${current.path}/${entry.name}`;
|
|
168
|
+
pending.push({ path, depth: current.depth + 1 });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
result.nested_projects.sort((a, b) => a.path.localeCompare(b.path));
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=local-test-config.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type LocalCheckDefinition } from './local-test-config.js';
|
|
2
|
+
import type { LocalTestCommandResult } from './local-test-command.js';
|
|
3
|
+
import type { LocalTestReport } from './local-test-results.js';
|
|
4
|
+
export declare const LOCAL_TEST_GATE_CONFIG = "blinkhost.gates.json";
|
|
5
|
+
export declare const LOCAL_TEST_GATE_LIMITS: {
|
|
6
|
+
readonly files: 1024;
|
|
7
|
+
readonly bytes: number;
|
|
8
|
+
readonly fileBytes: number;
|
|
9
|
+
};
|
|
10
|
+
declare const CATEGORIES: readonly ["source", "artifacts", "dependencies", "runtime", "resources", "fixtures"];
|
|
11
|
+
type Category = typeof CATEGORIES[number];
|
|
12
|
+
type Stage = 'preview' | 'promotion';
|
|
13
|
+
type Check = {
|
|
14
|
+
id: string;
|
|
15
|
+
kind: LocalCheckDefinition['kind'];
|
|
16
|
+
status: LocalTestCommandResult['status'] | 'not_run';
|
|
17
|
+
report?: LocalTestReport;
|
|
18
|
+
report_error?: string;
|
|
19
|
+
};
|
|
20
|
+
type Input = {
|
|
21
|
+
category: Category | 'configuration' | 'cli';
|
|
22
|
+
path: string;
|
|
23
|
+
sha256: string;
|
|
24
|
+
bytes: number;
|
|
25
|
+
};
|
|
26
|
+
export interface LocalTestGateReceipt {
|
|
27
|
+
schema: 'blinkhost.local-test-gate/v1';
|
|
28
|
+
stage: Stage;
|
|
29
|
+
status: 'passed' | 'blocked';
|
|
30
|
+
authority: 'customer_runner_reported';
|
|
31
|
+
scope: 'declared_local_inputs';
|
|
32
|
+
production_authority: false;
|
|
33
|
+
input_sha256: string;
|
|
34
|
+
observed_input_sha256: string | null;
|
|
35
|
+
inputs_unchanged: boolean | null;
|
|
36
|
+
inputs: Input[];
|
|
37
|
+
checks: Array<{
|
|
38
|
+
id: string;
|
|
39
|
+
status: 'passed' | 'blocked';
|
|
40
|
+
reason: string | null;
|
|
41
|
+
}>;
|
|
42
|
+
reason: string | null;
|
|
43
|
+
}
|
|
44
|
+
export interface PreparedLocalTestGate {
|
|
45
|
+
root: string;
|
|
46
|
+
stage: Stage;
|
|
47
|
+
required: string[];
|
|
48
|
+
paths: Array<{
|
|
49
|
+
category: Input['category'];
|
|
50
|
+
path: string;
|
|
51
|
+
filename: string;
|
|
52
|
+
}>;
|
|
53
|
+
inputs: Input[];
|
|
54
|
+
digest: string;
|
|
55
|
+
context: string;
|
|
56
|
+
executables: Array<{
|
|
57
|
+
command: string;
|
|
58
|
+
cwd: string;
|
|
59
|
+
filename: string;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
/** Bind configuration observed before validation to configuration used for execution. */
|
|
63
|
+
export declare function captureLocalTestGateConfiguration(root: string, deadline: number, signal?: AbortSignal): Promise<Input[]>;
|
|
64
|
+
/** A customer-local preflight, never a worker attestation or preview/promotion grant. */
|
|
65
|
+
export declare function prepareLocalTestGate(root: string, stage: string, definitions: LocalCheckDefinition[], limits: {
|
|
66
|
+
timeout_ms: number;
|
|
67
|
+
max_output_bytes: number;
|
|
68
|
+
}, deadline: number, signal?: AbortSignal, configuration?: Input[]): Promise<PreparedLocalTestGate>;
|
|
69
|
+
export declare function blockedLocalTestGate(prepared: PreparedLocalTestGate, checks: Check[], reason: string): LocalTestGateReceipt;
|
|
70
|
+
export declare function finishLocalTestGate(prepared: PreparedLocalTestGate, checks: Check[], deadline: number, signal?: AbortSignal): Promise<LocalTestGateReceipt>;
|
|
71
|
+
export {};
|