@buildr-ai/buildr 0.1.0-rc.21 → 0.1.0-rc.22
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/application-payload.json +167 -155
- package/installation-origin.json +5 -5
- package/package/targets/test-context/definition.d.ts +7 -0
- package/package/targets/test-context/definition.js +114 -0
- package/package/targets/test-context/index.d.ts +5 -0
- package/package/targets/test-context/index.js +4 -0
- package/package/targets/test-context/node-runner-cli.d.ts +2 -0
- package/package/targets/test-context/node-runner-cli.js +60 -0
- package/package/targets/test-context/node-runner.d.ts +2 -0
- package/package/targets/test-context/node-runner.js +86 -0
- package/package/targets/test-context/node-test.d.ts +14 -0
- package/package/targets/test-context/node-test.js +93 -0
- package/package/targets/test-context/runtime.d.ts +2 -0
- package/package/targets/test-context/runtime.js +342 -0
- package/package/targets/test-context/types.d.ts +216 -0
- package/package/targets/test-context/types.js +1 -0
- package/package.json +11 -1
- package/payload/licenses/dependencies/ajv-LICENSE +22 -0
- package/payload/product/package/targets/runtime/skills/buildr/SKILL.md +7 -7
- package/payload/product/package.json +2 -1
- package/payload/product/{package/bootstrap/contract.yml → resources/contracts/bootstrap.yml} +1 -1
- package/payload/product/{package → resources}/manifest.yml +95 -91
- package/payload/product/resources/workspace/AGENTS.md +9 -0
- package/payload/product/{package/targets → resources}/workspace/components/buildr/openspec/component.yml +3 -3
- package/payload/product/{package/targets → resources}/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +1 -1
- package/payload/product/{package/targets → resources}/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +1 -1
- package/payload/product/{package/targets → resources}/workspace/components/buildr/openspec/contributions/openspec-update-sidebar.md +1 -1
- package/payload/product/resources/workspace/rules/buildr/core.md +40 -0
- package/payload/product/{package/targets → resources}/workspace/skills/buildr/current-knowledge-maintenance/SKILL.md +4 -4
- package/payload/product/{package/targets → resources}/workspace/skills/buildr/declaration-intake/SKILL.md +14 -8
- package/payload/product/{package/targets → resources}/workspace/skills/buildr/git-operations/SKILL.md +5 -5
- package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-development/SKILL.md +34 -16
- package/payload/product/resources/workspace/skills/buildr/task-environment/SKILL.md +55 -0
- package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-environment/references/project-environment-preparation-v1.md +1 -1
- package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-environment/templates/task-environment-plan-request.json +2 -1
- package/payload/product/resources/workspace/skills/buildr/task-finish/SKILL.md +79 -0
- package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-manager/SKILL.md +9 -1
- package/payload/product/resources/workspace/skills/buildr/task-manager/agents/openai.yaml +4 -0
- package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-triage/SKILL.md +17 -9
- package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-verification/SKILL.md +23 -15
- package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-verification/references/project-verification-v2.md +3 -1
- package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-verification/templates/project-verification.yml +6 -0
- package/payload/product/{package/targets/workspace/skills/buildr/ui-preview → resources/workspace/skills/buildr/ui-prototype}/SKILL.md +14 -12
- package/payload/product/{package/targets → resources}/workspace/skills/contracts/buildr/current-knowledge-maintenance/v2.md +3 -3
- package/payload/product/{package/targets → resources}/workspace/skills/contracts/buildr/git-operations/v1.md +1 -1
- package/payload/product/resources/workspace/skills/contracts/buildr/task-development/v2.md +67 -0
- package/payload/product/resources/workspace/skills/contracts/buildr/task-environment/v1.md +37 -0
- package/payload/product/resources/workspace/skills/contracts/buildr/task-finish/v1.md +43 -0
- package/payload/product/{package/targets → resources}/workspace/skills/contracts/buildr/task-record/v2.md +1 -1
- package/payload/product/resources/workspace/skills/contracts/buildr/task-verification/v3.md +67 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0018_create_terminal_contribution_reconciliations.sql +19 -0
- package/payload/product/web-dist/assets/index-BnXBiObM.css +1 -0
- package/payload/product/web-dist/assets/index-CbM3dspL.js +39 -0
- package/payload/product/{src/interfaces/local-app/web-dist → web-dist}/index.html +2 -2
- package/payload/runtime/read-worker.cjs +53751 -34167
- package/runtime/buildr.cjs +53599 -39369
- package/test-context.mjs +12 -0
- package/payload/product/package/README.md +0 -42
- package/payload/product/package/targets/workspace/AGENTS.md +0 -5
- package/payload/product/package/targets/workspace/rules/buildr/core.md +0 -62
- package/payload/product/package/targets/workspace/skills/buildr/task-environment/SKILL.md +0 -42
- package/payload/product/package/targets/workspace/skills/buildr/task-finish/SKILL.md +0 -80
- package/payload/product/package/targets/workspace/skills/buildr/task-manager/agents/openai.yaml +0 -4
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-development/v2.md +0 -61
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-environment/v1.md +0 -37
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-finish/v1.md +0 -59
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-verification/v3.md +0 -63
- package/payload/product/src/interfaces/local-app/web-dist/assets/index-BqoyfMSY.css +0 -1
- package/payload/product/src/interfaces/local-app/web-dist/assets/index-DTqvE0TF.js +0 -39
- /package/payload/product/{package/bootstrap/guide.md → docs/bootstrap-guide.md} +0 -0
- /package/payload/product/{package/launchers/assets → resources/installation/launcher}/Buildr.icns +0 -0
- /package/payload/product/{package/launchers/assets → resources/installation/launcher}/Buildr.ico +0 -0
- /package/payload/product/{package/targets → resources}/workspace/commands/buildr/openspec/manifest.yml +0 -0
- /package/payload/product/{package/targets → resources}/workspace/components/buildr/openspec/contributions/openspec-archive-converge.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/components/buildr/openspec/contributions/openspec-explore-terminology.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/components/buildr/openspec/contributions/openspec-sync-converge.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/gitattributes +0 -0
- /package/payload/product/{package/targets → resources}/workspace/gitignore +0 -0
- /package/payload/product/{package/targets → resources}/workspace/projects/AGENTS.project.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/capability-adaptation/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/capability-adaptation/agents/openai.yaml +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/openspec-contract-guard/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/project-daily-progress/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/project-testing/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/project-testing/references/testing-model-v1.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-environment/agents/openai.yaml +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-environment/templates/project-preparation.yml +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-retrospective/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-retrospective/agents/openai.yaml +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-review/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-review/agents/openai.yaml +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/task-worktree/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/buildr/terminology-governance/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/contracts/buildr/current-knowledge-maintenance/v1.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/contracts/buildr/git-worktree-provider/v1.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/contracts/buildr/task-retrospective/v2.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/contracts/buildr/task-review/v1.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/contracts/buildr/terminology-governance/v1.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/openspec/openspec-apply-change/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/openspec/openspec-archive-change/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/openspec/openspec-explore/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/openspec/openspec-propose/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/openspec/openspec-sync-specs/SKILL.md +0 -0
- /package/payload/product/{package/targets → resources}/workspace/skills/openspec/openspec-update-change/SKILL.md +0 -0
- /package/payload/product/{src/interfaces/local-app/web-dist → web-dist}/assets/antd-NAtxFWmu.js +0 -0
- /package/payload/product/{src/interfaces/local-app/web-dist → web-dist}/assets/react-9kRp7SbA.js +0 -0
package/installation-origin.json
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
"channel": "npm",
|
|
4
4
|
"runtimeRole": "host",
|
|
5
5
|
"package": "@buildr-ai/buildr",
|
|
6
|
-
"version": "0.1.0-rc.
|
|
6
|
+
"version": "0.1.0-rc.22",
|
|
7
7
|
"protocolIdentity": "buildr.web-protocol/v1",
|
|
8
|
-
"applicationPayloadDigest": "sha256-
|
|
9
|
-
"sourceCommit": "
|
|
8
|
+
"applicationPayloadDigest": "sha256-6cfb41052a1331c1ee8f13d176a4b07391f8ff93d18b470d4d68fdd126649034",
|
|
9
|
+
"sourceCommit": "dd122537116e968fe6b2e15a743dde06e8f114bb",
|
|
10
10
|
"sourceTag": null,
|
|
11
|
-
"installUnit": "@buildr-ai/buildr@0.1.0-rc.
|
|
12
|
-
"ownershipIdentity": "sha256-
|
|
11
|
+
"installUnit": "@buildr-ai/buildr@0.1.0-rc.22",
|
|
12
|
+
"ownershipIdentity": "sha256-cfb53920596d4e7a6f972db52717b880b5c0f5bbfd2fecc6d666747354999b28"
|
|
13
13
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyTestContextDefinition, JsonValue, NormalizedTestContextRequest, TestContextDefinition, TestContextDefinitionInput, TestContextDependency, TestContextError, TestContextRequest } from './types.js';
|
|
2
|
+
export declare function testContextError(code: string, message: string, details?: Record<string, unknown>): TestContextError;
|
|
3
|
+
export declare function canonicalContextConfiguration(value?: unknown): string;
|
|
4
|
+
export declare function contextConfigurationIdentity(value?: unknown): string;
|
|
5
|
+
export declare function isTestContextDefinition(value: unknown): value is AnyTestContextDefinition;
|
|
6
|
+
export declare function defineTestContext<const Id extends string, State, Config extends JsonValue = Record<string, never>, Acquired = State, const Dependencies extends readonly TestContextDependency[] = readonly []>(input: TestContextDefinitionInput<Id, State, Config, Acquired, Dependencies>): TestContextDefinition<Id, State, Config, Acquired>;
|
|
7
|
+
export declare function normalizeContextRequest<Definition extends AnyTestContextDefinition>(value: TestContextRequest<Definition>, alias?: string | null): NormalizedTestContextRequest<Definition>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
const DEFINITION = Symbol.for('@buildr-ai/test-context/definition');
|
|
3
|
+
const KEY_PATTERN = /^[a-z0-9][a-z0-9-]*(?:\.[a-z0-9][a-z0-9-]*)*$/;
|
|
4
|
+
const SCOPES = new Set(['worker', 'suite', 'test']);
|
|
5
|
+
const PARALLEL_SAFETY = new Set(['shared', 'exclusive', 'isolated']);
|
|
6
|
+
export function testContextError(code, message, details = {}) {
|
|
7
|
+
const error = new Error(`${code}: ${message}`);
|
|
8
|
+
error.code = code;
|
|
9
|
+
error.details = Object.freeze({ ...details });
|
|
10
|
+
return error;
|
|
11
|
+
}
|
|
12
|
+
function plainObject(value) {
|
|
13
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
14
|
+
return false;
|
|
15
|
+
const prototype = Object.getPrototypeOf(value);
|
|
16
|
+
return prototype === Object.prototype || prototype === null;
|
|
17
|
+
}
|
|
18
|
+
function normalizeSerializable(value, location = '$', seen = new Set()) {
|
|
19
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
20
|
+
return value;
|
|
21
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
22
|
+
return Object.is(value, -0) ? 0 : value;
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
if (seen.has(value))
|
|
25
|
+
throw testContextError('test_context_configuration_invalid', 'Context configuration must not contain cycles.', { location });
|
|
26
|
+
seen.add(value);
|
|
27
|
+
const result = value.map((item, index) => normalizeSerializable(item, `${location}[${index}]`, seen));
|
|
28
|
+
seen.delete(value);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
if (plainObject(value)) {
|
|
32
|
+
if (seen.has(value))
|
|
33
|
+
throw testContextError('test_context_configuration_invalid', 'Context configuration must not contain cycles.', { location });
|
|
34
|
+
seen.add(value);
|
|
35
|
+
const result = {};
|
|
36
|
+
for (const key of Object.keys(value).sort()) {
|
|
37
|
+
if (value[key] === undefined)
|
|
38
|
+
throw testContextError('test_context_configuration_invalid', 'Context configuration must not contain undefined values.', { location: `${location}.${key}` });
|
|
39
|
+
result[key] = normalizeSerializable(value[key], `${location}.${key}`, seen);
|
|
40
|
+
}
|
|
41
|
+
seen.delete(value);
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
throw testContextError('test_context_configuration_invalid', 'Context configuration must contain only deterministic JSON values.', { location, type: typeof value });
|
|
45
|
+
}
|
|
46
|
+
export function canonicalContextConfiguration(value = {}) {
|
|
47
|
+
return JSON.stringify(normalizeSerializable(value));
|
|
48
|
+
}
|
|
49
|
+
export function contextConfigurationIdentity(value = {}) {
|
|
50
|
+
return `sha256-${crypto.createHash('sha256').update(canonicalContextConfiguration(value)).digest('hex')}`;
|
|
51
|
+
}
|
|
52
|
+
export function isTestContextDefinition(value) {
|
|
53
|
+
return Boolean(value?.[DEFINITION]);
|
|
54
|
+
}
|
|
55
|
+
function dependencyDefinition(value, owner) {
|
|
56
|
+
const dependency = isTestContextDefinition(value) ? { definition: value } : value;
|
|
57
|
+
if (!plainObject(dependency) || !isTestContextDefinition(dependency.definition)) {
|
|
58
|
+
throw testContextError('test_context_definition_invalid', `Context ${owner} has an invalid dependency.`);
|
|
59
|
+
}
|
|
60
|
+
if (dependency.config != null && typeof dependency.config !== 'function' && !plainObject(dependency.config)) {
|
|
61
|
+
throw testContextError('test_context_definition_invalid', `Context ${owner} dependency config must be an object or function.`);
|
|
62
|
+
}
|
|
63
|
+
return Object.freeze({
|
|
64
|
+
definition: dependency.definition,
|
|
65
|
+
config: (dependency.config ?? {}),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export function defineTestContext(input) {
|
|
69
|
+
if (!plainObject(input))
|
|
70
|
+
throw testContextError('test_context_definition_invalid', 'Context definition must be an object.');
|
|
71
|
+
if (!KEY_PATTERN.test(input.id ?? ''))
|
|
72
|
+
throw testContextError('test_context_definition_invalid', 'Context id must be a stable kebab/dotted identifier.', { id: input.id ?? null });
|
|
73
|
+
if (!Number.isInteger(input.version) || input.version < 1)
|
|
74
|
+
throw testContextError('test_context_definition_invalid', `Context ${input.id} version must be a positive integer.`);
|
|
75
|
+
if (!SCOPES.has(input.scope))
|
|
76
|
+
throw testContextError('test_context_definition_invalid', `Context ${input.id} has an invalid scope.`, { scope: input.scope });
|
|
77
|
+
if (!PARALLEL_SAFETY.has(input.parallelSafety))
|
|
78
|
+
throw testContextError('test_context_definition_invalid', `Context ${input.id} has invalid parallel safety.`, { parallelSafety: input.parallelSafety });
|
|
79
|
+
if (typeof input.create !== 'function')
|
|
80
|
+
throw testContextError('test_context_definition_invalid', `Context ${input.id} is missing create().`);
|
|
81
|
+
for (const hook of ['acquire', 'release', 'reset', 'inspect', 'destroy']) {
|
|
82
|
+
if (input[hook] != null && typeof input[hook] !== 'function')
|
|
83
|
+
throw testContextError('test_context_definition_invalid', `Context ${input.id} ${hook} must be a function.`);
|
|
84
|
+
}
|
|
85
|
+
if (input.sourceIdentity != null && typeof input.sourceIdentity !== 'string' && typeof input.sourceIdentity !== 'function') {
|
|
86
|
+
throw testContextError('test_context_definition_invalid', `Context ${input.id} sourceIdentity must be a string or function.`);
|
|
87
|
+
}
|
|
88
|
+
const key = `${input.id}/v${input.version}`;
|
|
89
|
+
const definition = {
|
|
90
|
+
[DEFINITION]: true,
|
|
91
|
+
id: input.id,
|
|
92
|
+
version: input.version,
|
|
93
|
+
key,
|
|
94
|
+
scope: input.scope,
|
|
95
|
+
parallelSafety: input.parallelSafety,
|
|
96
|
+
dependencies: Object.freeze((input.dependencies ?? []).map((item) => dependencyDefinition(item, key))),
|
|
97
|
+
create: input.create,
|
|
98
|
+
acquire: input.acquire ?? null,
|
|
99
|
+
release: input.release ?? null,
|
|
100
|
+
reset: input.reset ?? null,
|
|
101
|
+
inspect: input.inspect ?? null,
|
|
102
|
+
destroy: input.destroy ?? null,
|
|
103
|
+
sourceIdentity: input.sourceIdentity ?? null,
|
|
104
|
+
};
|
|
105
|
+
return Object.freeze(definition);
|
|
106
|
+
}
|
|
107
|
+
export function normalizeContextRequest(value, alias = null) {
|
|
108
|
+
const request = isTestContextDefinition(value) ? { definition: value } : value;
|
|
109
|
+
if (!request || !isTestContextDefinition(request.definition))
|
|
110
|
+
throw testContextError('test_context_request_invalid', 'Context request must reference a definition.', { alias });
|
|
111
|
+
const config = (request.config ?? {});
|
|
112
|
+
canonicalContextConfiguration(config);
|
|
113
|
+
return Object.freeze({ alias: alias ?? request.definition.id, definition: request.definition, config });
|
|
114
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { canonicalContextConfiguration, contextConfigurationIdentity, defineTestContext, isTestContextDefinition, normalizeContextRequest, testContextError, } from './definition.js';
|
|
2
|
+
export { createTestContextRuntime } from './runtime.js';
|
|
3
|
+
export { closeDefaultNodeTestContextRuntime, contextTest, createNodeTestContextAdapter, defaultNodeTestContextRuntime, } from './node-test.js';
|
|
4
|
+
export { runNodeTestContextHosts } from './node-runner.js';
|
|
5
|
+
export type { AnyTestContextDefinition, CheckedTestContextRequests, ContextTestCallback, ContextTestOptions, JsonObject, JsonValue, NodeTestContextAdapter, NodeTestContextFile, NodeTestContextHostResult, NodeTestContextRunOptions, NodeTestContextRunResult, NormalizedTestContextDependency, NormalizedTestContextRequest, TestContextAcquireHook, TestContextCreateHook, TestContextDefinition, TestContextDefinitionInput, TestContextDependency, TestContextDependencyValues, TestContextDestroyHook, TestContextError, TestContextEvent, TestContextInspection, TestContextLease, TestContextLeaseControl, TestContextOwner, TestContextParallelSafety, TestContextReleaseHook, TestContextRequest, TestContextRequests, TestContextResetHook, TestContextRuntime, TestContextRuntimeOptions, TestContextScope, TestContextValues, } from './types.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { canonicalContextConfiguration, contextConfigurationIdentity, defineTestContext, isTestContextDefinition, normalizeContextRequest, testContextError, } from './definition.js';
|
|
2
|
+
export { createTestContextRuntime } from './runtime.js';
|
|
3
|
+
export { closeDefaultNodeTestContextRuntime, contextTest, createNodeTestContextAdapter, defaultNodeTestContextRuntime, } from './node-test.js';
|
|
4
|
+
export { runNodeTestContextHosts } from './node-runner.js';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { runNodeTestContextHosts } from './node-runner.js';
|
|
4
|
+
function option(args, name, fallback = null) {
|
|
5
|
+
const index = args.indexOf(name);
|
|
6
|
+
if (index === -1)
|
|
7
|
+
return fallback;
|
|
8
|
+
const value = args[index + 1];
|
|
9
|
+
if (!value || value.startsWith('--'))
|
|
10
|
+
throw new Error(`Missing value for ${name}`);
|
|
11
|
+
args.splice(index, 2);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const args = process.argv.slice(2);
|
|
16
|
+
const workers = Number.parseInt(option(args, '--workers', '1'), 10);
|
|
17
|
+
const cwd = option(args, '--cwd', process.cwd());
|
|
18
|
+
if (args.some((item) => item.startsWith('--')))
|
|
19
|
+
throw new Error(`Unknown option: ${args.find((item) => item.startsWith('--'))}`);
|
|
20
|
+
const result = await runNodeTestContextHosts({ cwd, workers, files: args });
|
|
21
|
+
for (const host of result.hosts) {
|
|
22
|
+
process.stdout.write(`# Context Worker Host ${host.host}: ${host.files.length} file(s)\n`);
|
|
23
|
+
process.stdout.write(host.stdout);
|
|
24
|
+
process.stderr.write(host.stderr);
|
|
25
|
+
}
|
|
26
|
+
const count = (operation) => result.events.filter((event) => event.operation === operation).length;
|
|
27
|
+
const duration = (operation) => result.events.filter((event) => event.operation === operation)
|
|
28
|
+
.reduce((total, event) => total + (event.durationMs ?? 0), 0);
|
|
29
|
+
const summary = {
|
|
30
|
+
schemaVersion: 'node.test-context-summary/v1',
|
|
31
|
+
hosts: result.workerCount,
|
|
32
|
+
creates: count('create'),
|
|
33
|
+
cacheHits: count('cache-hit'),
|
|
34
|
+
acquires: count('acquire'),
|
|
35
|
+
releases: count('release'),
|
|
36
|
+
resets: count('reset'),
|
|
37
|
+
dirty: count('dirty'),
|
|
38
|
+
evicts: count('evict'),
|
|
39
|
+
destroys: count('destroy'),
|
|
40
|
+
waits: count('wait'),
|
|
41
|
+
createDurationMs: duration('create'),
|
|
42
|
+
acquireDurationMs: duration('acquire'),
|
|
43
|
+
releaseDurationMs: duration('release'),
|
|
44
|
+
waitDurationMs: duration('wait'),
|
|
45
|
+
resetDurationMs: duration('reset'),
|
|
46
|
+
destroyDurationMs: duration('destroy'),
|
|
47
|
+
materializeDurationMs: duration('provider-materialize'),
|
|
48
|
+
cleanupDurationMs: duration('provider-cleanup'),
|
|
49
|
+
testBodyDurationMs: duration('test-body'),
|
|
50
|
+
durationMs: result.durationMs,
|
|
51
|
+
wallClockDurationMs: result.durationMs,
|
|
52
|
+
};
|
|
53
|
+
process.stdout.write(`# node-test-context-summary ${JSON.stringify(summary)}\n`);
|
|
54
|
+
process.exitCode = result.status === 'passed' ? 0 : 1;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const failure = error;
|
|
58
|
+
process.stderr.write(`${failure.stack || failure.message}\n`);
|
|
59
|
+
process.exitCode = 2;
|
|
60
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
function normalizeFiles(files, cwd) {
|
|
7
|
+
const result = files.map((item) => typeof item === 'string' ? { file: item, signature: 'default' } : item);
|
|
8
|
+
for (const item of result) {
|
|
9
|
+
if (!item || typeof item.file !== 'string' || !item.file)
|
|
10
|
+
throw new Error('node_test_context_runner_input_invalid: each file descriptor requires file.');
|
|
11
|
+
if (item.signature != null && typeof item.signature !== 'string')
|
|
12
|
+
throw new Error('node_test_context_runner_input_invalid: file signature must be a string.');
|
|
13
|
+
}
|
|
14
|
+
return result.map((item) => ({ file: path.resolve(cwd, item.file), signature: item.signature ?? 'default' }))
|
|
15
|
+
.sort((left, right) => left.signature.localeCompare(right.signature) || left.file.localeCompare(right.file));
|
|
16
|
+
}
|
|
17
|
+
function partition(files, workerCount) {
|
|
18
|
+
const groups = Array.from({ length: workerCount }, () => []);
|
|
19
|
+
for (const item of files) {
|
|
20
|
+
const target = groups.reduce((best, group) => group.length < best.length ? group : best, groups[0]);
|
|
21
|
+
target.push(item);
|
|
22
|
+
}
|
|
23
|
+
return groups.filter((group) => group.length > 0);
|
|
24
|
+
}
|
|
25
|
+
function runHost(input, options) {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const child = spawn(options.nodeExecutable, [
|
|
28
|
+
'--test',
|
|
29
|
+
'--test-isolation=none',
|
|
30
|
+
'--test-concurrency=1',
|
|
31
|
+
...input.files,
|
|
32
|
+
], {
|
|
33
|
+
cwd: input.cwd,
|
|
34
|
+
env: {
|
|
35
|
+
...options.env,
|
|
36
|
+
NODE_TEST_CONTEXT_HOST: '1',
|
|
37
|
+
NODE_TEST_CONTEXT_EVENTS_FILE: input.eventsFile,
|
|
38
|
+
},
|
|
39
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
40
|
+
});
|
|
41
|
+
let stdout = '';
|
|
42
|
+
let stderr = '';
|
|
43
|
+
child.stdout.setEncoding('utf8');
|
|
44
|
+
child.stderr.setEncoding('utf8');
|
|
45
|
+
child.stdout.on('data', (chunk) => { stdout += chunk; });
|
|
46
|
+
child.stderr.on('data', (chunk) => { stderr += chunk; });
|
|
47
|
+
child.on('error', (error) => resolve({ status: 'failed', exitCode: null, signal: null, stdout, stderr: `${stderr}${error.stack || error.message}\n` }));
|
|
48
|
+
child.on('close', (exitCode, signal) => resolve({ status: exitCode === 0 ? 'passed' : 'failed', exitCode, signal, stdout, stderr }));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export async function runNodeTestContextHosts(options) {
|
|
52
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
53
|
+
const files = normalizeFiles(options.files ?? [], cwd);
|
|
54
|
+
if (files.length === 0)
|
|
55
|
+
throw new Error('node_test_context_runner_input_invalid: at least one file is required.');
|
|
56
|
+
const requestedWorkers = options.workers ?? 1;
|
|
57
|
+
if (!Number.isInteger(requestedWorkers) || requestedWorkers < 1)
|
|
58
|
+
throw new Error('node_test_context_runner_input_invalid: workers must be a positive integer.');
|
|
59
|
+
const workerCount = Math.min(requestedWorkers, files.length);
|
|
60
|
+
const groups = partition(files, workerCount);
|
|
61
|
+
const temporaryRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'node-test-context-hosts-'));
|
|
62
|
+
const startedAt = Date.now();
|
|
63
|
+
try {
|
|
64
|
+
const results = await Promise.all(groups.map(async (group, index) => {
|
|
65
|
+
const eventsFile = path.join(temporaryRoot, `host-${index + 1}.ndjson`);
|
|
66
|
+
const result = await runHost({ cwd, files: group.map((item) => item.file), eventsFile }, {
|
|
67
|
+
nodeExecutable: options.nodeExecutable ?? process.execPath,
|
|
68
|
+
env: { ...process.env, ...options.env },
|
|
69
|
+
});
|
|
70
|
+
const events = fs.statSync(eventsFile, { throwIfNoEntry: false })?.isFile()
|
|
71
|
+
? fs.readFileSync(eventsFile, 'utf8').split('\n').filter(Boolean).map((line) => JSON.parse(line))
|
|
72
|
+
: [];
|
|
73
|
+
return Object.freeze({ host: index + 1, files: Object.freeze(group.map((item) => item.file)), events: Object.freeze(events), ...result });
|
|
74
|
+
}));
|
|
75
|
+
return Object.freeze({
|
|
76
|
+
status: results.every((result) => result.status === 'passed') ? 'passed' : 'failed',
|
|
77
|
+
workerCount: groups.length,
|
|
78
|
+
durationMs: Date.now() - startedAt,
|
|
79
|
+
hosts: Object.freeze(results),
|
|
80
|
+
events: Object.freeze(results.flatMap((result) => result.events.map((event) => ({ host: result.host, ...event })))),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
fs.rmSync(temporaryRoot, { recursive: true, force: true });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ContextTestCallback, ContextTestOptions, NodeTestContextAdapter, TestContextRequests, TestContextRuntime } from './types.js';
|
|
2
|
+
export declare function defaultNodeTestContextRuntime(): TestContextRuntime;
|
|
3
|
+
export declare function closeDefaultNodeTestContextRuntime(): Promise<Readonly<{
|
|
4
|
+
status: string;
|
|
5
|
+
events?: readonly unknown[];
|
|
6
|
+
}>>;
|
|
7
|
+
interface CreateNodeTestContextAdapterOptions {
|
|
8
|
+
runtime?: TestContextRuntime;
|
|
9
|
+
test?: (name: string, options: object, callback: (context: any) => Promise<unknown>) => unknown;
|
|
10
|
+
suiteId?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function createNodeTestContextAdapter(options?: CreateNodeTestContextAdapterOptions): NodeTestContextAdapter;
|
|
13
|
+
export declare function contextTest<Requests extends TestContextRequests>(name: string, options: ContextTestOptions<Requests>, callback: ContextTestCallback<Requests>): unknown;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import nodeTest, { after } from 'node:test';
|
|
3
|
+
import { createTestContextRuntime } from './runtime.js';
|
|
4
|
+
const DEFAULT_RUNTIME = Symbol.for('@buildr-ai/test-context/default-node-runtime');
|
|
5
|
+
const DEFAULT_ADAPTER = Symbol.for('@buildr-ai/test-context/default-node-adapter');
|
|
6
|
+
const DIRECT_HOOK = Symbol.for('@buildr-ai/test-context/direct-close-hook');
|
|
7
|
+
const HOST_HOOK = Symbol.for('@buildr-ai/test-context/host-close-hook');
|
|
8
|
+
const globalState = globalThis;
|
|
9
|
+
export function defaultNodeTestContextRuntime() {
|
|
10
|
+
globalState[DEFAULT_RUNTIME] ??= createTestContextRuntime({
|
|
11
|
+
onEvent: process.env.NODE_TEST_CONTEXT_EVENTS_FILE
|
|
12
|
+
? (event) => fs.appendFileSync(process.env.NODE_TEST_CONTEXT_EVENTS_FILE, `${JSON.stringify(event)}\n`)
|
|
13
|
+
: undefined,
|
|
14
|
+
});
|
|
15
|
+
return globalState[DEFAULT_RUNTIME];
|
|
16
|
+
}
|
|
17
|
+
export async function closeDefaultNodeTestContextRuntime() {
|
|
18
|
+
const runtime = globalState[DEFAULT_RUNTIME];
|
|
19
|
+
if (!runtime)
|
|
20
|
+
return Object.freeze({ status: 'not-created' });
|
|
21
|
+
delete globalState[DEFAULT_ADAPTER];
|
|
22
|
+
delete globalState[DEFAULT_RUNTIME];
|
|
23
|
+
return runtime.close();
|
|
24
|
+
}
|
|
25
|
+
function splitOptions(options) {
|
|
26
|
+
const { contexts, suiteId, ...nodeOptions } = options;
|
|
27
|
+
return { contexts, suiteId, nodeOptions };
|
|
28
|
+
}
|
|
29
|
+
export function createNodeTestContextAdapter(options = {}) {
|
|
30
|
+
const runtime = options.runtime ?? defaultNodeTestContextRuntime();
|
|
31
|
+
const implementation = options.test ?? nodeTest;
|
|
32
|
+
const defaultSuiteId = options.suiteId ?? 'node-test-context';
|
|
33
|
+
let registration = 0;
|
|
34
|
+
const contextTest = (name, testOptions, callback) => {
|
|
35
|
+
if (typeof callback !== 'function')
|
|
36
|
+
throw new TypeError('Context test callback is required.');
|
|
37
|
+
const current = splitOptions(testOptions);
|
|
38
|
+
if (!current.contexts || Object.keys(current.contexts).length === 0)
|
|
39
|
+
throw new TypeError('Context test requires at least one contexts entry.');
|
|
40
|
+
const testId = `${defaultSuiteId}:${++registration}:${name}`;
|
|
41
|
+
return implementation(name, current.nodeOptions, async (t) => {
|
|
42
|
+
const acquire = runtime.acquire;
|
|
43
|
+
const lease = await acquire(current.contexts, { suiteId: current.suiteId ?? defaultSuiteId, testId, name });
|
|
44
|
+
const bodyStartedAt = Date.now();
|
|
45
|
+
let outcome = 'passed';
|
|
46
|
+
let bodyFailure = null;
|
|
47
|
+
try {
|
|
48
|
+
return await callback(t, lease.values, Object.freeze({ identities: lease.identities, markDirty: lease.markDirty.bind(lease) }));
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
outcome = 'failed';
|
|
52
|
+
bodyFailure = error;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
runtime.record({ operation: 'test-body', testId, name, status: outcome, durationMs: Date.now() - bodyStartedAt });
|
|
57
|
+
try {
|
|
58
|
+
await lease.release({ outcome });
|
|
59
|
+
}
|
|
60
|
+
catch (releaseFailure) {
|
|
61
|
+
if (bodyFailure)
|
|
62
|
+
throw new AggregateError([bodyFailure, releaseFailure], 'Test body and Context release both failed.');
|
|
63
|
+
throw releaseFailure;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
return Object.freeze({ test: contextTest, runtime });
|
|
69
|
+
}
|
|
70
|
+
function defaultNodeTestContextAdapter() {
|
|
71
|
+
globalState[DEFAULT_ADAPTER] ??= createNodeTestContextAdapter();
|
|
72
|
+
return globalState[DEFAULT_ADAPTER];
|
|
73
|
+
}
|
|
74
|
+
export function contextTest(name, options, callback) {
|
|
75
|
+
if (process.env.NODE_TEST_CONTEXT_HOST && !globalState[HOST_HOOK]) {
|
|
76
|
+
globalState[HOST_HOOK] = true;
|
|
77
|
+
process.once('beforeExit', async () => {
|
|
78
|
+
try {
|
|
79
|
+
await closeDefaultNodeTestContextRuntime();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const failure = error;
|
|
83
|
+
process.stderr.write(`# node-test-context close failed: ${failure.stack || failure.message}\n`);
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else if (!process.env.NODE_TEST_CONTEXT_HOST && !globalState[DIRECT_HOOK]) {
|
|
89
|
+
globalState[DIRECT_HOOK] = true;
|
|
90
|
+
after(async () => closeDefaultNodeTestContextRuntime());
|
|
91
|
+
}
|
|
92
|
+
return defaultNodeTestContextAdapter().test(name, options, callback);
|
|
93
|
+
}
|