@dharma-ai-labs/agent-fabric-task-runner 0.1.43 → 0.1.45
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 +76 -0
- package/dist/acceptanceEnvironment.d.ts +51 -0
- package/dist/acceptanceEnvironment.d.ts.map +1 -0
- package/dist/acceptanceEnvironment.js +96 -0
- package/dist/acceptanceEnvironment.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -9
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +342 -42
- package/dist/index.test.js.map +1 -1
- package/dist/registeredCommandEnvironment.test.d.ts +2 -0
- package/dist/registeredCommandEnvironment.test.d.ts.map +1 -0
- package/dist/registeredCommandEnvironment.test.js +74 -0
- package/dist/registeredCommandEnvironment.test.js.map +1 -0
- package/package.json +2 -2
package/dist/index.test.js
CHANGED
|
@@ -8,6 +8,7 @@ import childProcess, { spawnSync } from 'node:child_process';
|
|
|
8
8
|
import { syncBuiltinESMExports } from 'node:module';
|
|
9
9
|
import { actionDecisionDigest, signCanonicalObject, validateTaskEnvelopeContract, validateTaskActionContract, } from '@dharma-ai-labs/agent-fabric-contracts';
|
|
10
10
|
import { assertTaskWithinLocalPolicy, canonicalTaskActionForTask, executeTask, FileActionDecisionReplayGuard, FileActionExecutionJournal, FileTaskReceiptStore, providerInstructionsForTask, verifyTaskEnvelope, } from './index.js';
|
|
11
|
+
import * as taskRunner from './index.js';
|
|
11
12
|
async function requiredArtifactFixture(t, requiredArtifacts) {
|
|
12
13
|
const root = await mkdtemp(resolve(tmpdir(), 'dharma-required-artifact-'));
|
|
13
14
|
t.after(() => rm(root, { recursive: true, force: true }));
|
|
@@ -15,7 +16,7 @@ async function requiredArtifactFixture(t, requiredArtifacts) {
|
|
|
15
16
|
await mkdir(workspace);
|
|
16
17
|
for (const argv of [['init', '-q'], ['config', 'user.email', 'test@dharma.ai'],
|
|
17
18
|
['config', 'user.name', 'Artifact Fixture'], ['commit', '--allow-empty', '-qm', 'initial']]) {
|
|
18
|
-
assert.equal(spawnSync('git', argv, { cwd: workspace }).status, 0);
|
|
19
|
+
assert.equal(spawnSync('git', argv, { cwd: workspace, windowsHide: true }).status, 0);
|
|
19
20
|
}
|
|
20
21
|
const policy = {
|
|
21
22
|
schema: 'dharma.organization-policy/v1', organizationId: 'org_test', revision: '1',
|
|
@@ -49,6 +50,13 @@ async function requiredArtifactFixture(t, requiredArtifacts) {
|
|
|
49
50
|
input: { policy, workspace, relayStateDirectory: resolve(root, 'state'), serverPublicKey: publicKey,
|
|
50
51
|
receiptStore: new FileTaskReceiptStore(resolve(root, 'receipts')) } };
|
|
51
52
|
}
|
|
53
|
+
// Relay-internal Git calls start with `-c name=value` configuration overrides.
|
|
54
|
+
function gitSubcommand(argv) {
|
|
55
|
+
let index = 0;
|
|
56
|
+
while (argv[index] === '-c')
|
|
57
|
+
index += 2;
|
|
58
|
+
return argv[index];
|
|
59
|
+
}
|
|
52
60
|
test('required artifact review v10: incomplete Git streams fail closed', async (t) => {
|
|
53
61
|
for (const stream of ['tracked-overflow', 'untracked-overflow', 'unterminated']) {
|
|
54
62
|
await t.test(stream, async (child) => {
|
|
@@ -60,11 +68,11 @@ test('required artifact review v10: incomplete Git streams fail closed', async (
|
|
|
60
68
|
await writeFile(outputPath, body);
|
|
61
69
|
let intercepted = 0;
|
|
62
70
|
const patch = child.mock.method(childProcess, 'spawn', (command, argv, options) => {
|
|
63
|
-
if (command === 'git' && (stream === 'untracked-overflow' ?
|
|
71
|
+
if (command === 'git' && gitSubcommand(argv) === (stream === 'untracked-overflow' ? 'ls-files' : 'diff')) {
|
|
64
72
|
intercepted++;
|
|
65
|
-
return originalSpawn(process.execPath, ['-e', 'process.stdout.write(require("node:fs").readFileSync(process.argv[1]));', outputPath], options);
|
|
73
|
+
return originalSpawn(process.execPath, ['-e', 'process.stdout.write(require("node:fs").readFileSync(process.argv[1]));', outputPath], { ...options, windowsHide: true });
|
|
66
74
|
}
|
|
67
|
-
return originalSpawn(command, argv, options);
|
|
75
|
+
return originalSpawn(command, argv, { ...options, windowsHide: true });
|
|
68
76
|
});
|
|
69
77
|
syncBuiltinESMExports();
|
|
70
78
|
try {
|
|
@@ -88,8 +96,8 @@ test('required artifact review v10: incomplete Git streams fail closed', async (
|
|
|
88
96
|
test('required artifact review v10: ignored outputs require signed write authority', async (t) => {
|
|
89
97
|
const fixture = await requiredArtifactFixture(t, ['reports/result.json']);
|
|
90
98
|
await writeFile(resolve(fixture.workspace, '.gitignore'), 'reports/result.json\n');
|
|
91
|
-
assert.equal(spawnSync('git', ['add', '.gitignore'], { cwd: fixture.workspace }).status, 0);
|
|
92
|
-
assert.equal(spawnSync('git', ['commit', '-qm', 'ignore output'], { cwd: fixture.workspace }).status, 0);
|
|
99
|
+
assert.equal(spawnSync('git', ['add', '.gitignore'], { cwd: fixture.workspace, windowsHide: true }).status, 0);
|
|
100
|
+
assert.equal(spawnSync('git', ['commit', '-qm', 'ignore output'], { cwd: fixture.workspace, windowsHide: true }).status, 0);
|
|
93
101
|
fixture.unsigned.authority.writePaths = ['reports/allowed/**'];
|
|
94
102
|
let calls = 0;
|
|
95
103
|
const receipt = await executeTask({ ...fixture.input, task: fixture.signed(),
|
|
@@ -109,8 +117,8 @@ test('required artifact review v10: existing read-only artifacts remain unchange
|
|
|
109
117
|
const fixture = await requiredArtifactFixture(child, ['reports/result.json']);
|
|
110
118
|
await mkdir(resolve(fixture.workspace, 'reports'));
|
|
111
119
|
await writeFile(resolve(fixture.workspace, 'reports/result.json'), 'private-read-only-sentinel');
|
|
112
|
-
assert.equal(spawnSync('git', ['add', 'reports/result.json'], { cwd: fixture.workspace }).status, 0);
|
|
113
|
-
assert.equal(spawnSync('git', ['commit', '-qm', 'existing output'], { cwd: fixture.workspace }).status, 0);
|
|
120
|
+
assert.equal(spawnSync('git', ['add', 'reports/result.json'], { cwd: fixture.workspace, windowsHide: true }).status, 0);
|
|
121
|
+
assert.equal(spawnSync('git', ['commit', '-qm', 'existing output'], { cwd: fixture.workspace, windowsHide: true }).status, 0);
|
|
114
122
|
fixture.unsigned.authority.writePaths = ['reports/allowed/**'];
|
|
115
123
|
if (mutate) {
|
|
116
124
|
fixture.policy.tasks.allowedCommands.verify = { argv: [process.execPath, '-e',
|
|
@@ -130,8 +138,8 @@ test('required artifact review v10: existing read-only artifacts remain unchange
|
|
|
130
138
|
test('required artifact review v10: ignored write-authorized outputs remain supported', async (t) => {
|
|
131
139
|
const fixture = await requiredArtifactFixture(t, ['reports/result.json']);
|
|
132
140
|
await writeFile(resolve(fixture.workspace, '.gitignore'), 'reports/result.json\n');
|
|
133
|
-
assert.equal(spawnSync('git', ['add', '.gitignore'], { cwd: fixture.workspace }).status, 0);
|
|
134
|
-
assert.equal(spawnSync('git', ['commit', '-qm', 'ignore output'], { cwd: fixture.workspace }).status, 0);
|
|
141
|
+
assert.equal(spawnSync('git', ['add', '.gitignore'], { cwd: fixture.workspace, windowsHide: true }).status, 0);
|
|
142
|
+
assert.equal(spawnSync('git', ['commit', '-qm', 'ignore output'], { cwd: fixture.workspace, windowsHide: true }).status, 0);
|
|
135
143
|
const receipt = await executeTask({ ...fixture.input, task: fixture.signed(), providerExecutor: async ({ workspace }) => {
|
|
136
144
|
await mkdir(resolve(workspace, 'reports'));
|
|
137
145
|
await writeFile(resolve(workspace, 'reports/result.json'), '{}');
|
|
@@ -401,7 +409,7 @@ test('required artifact review v4: Git preserves Unicode paths in tracked and un
|
|
|
401
409
|
await mkdir(resolve(workspace, 'reports'));
|
|
402
410
|
await writeFile(resolve(workspace, artifact), '{}');
|
|
403
411
|
if (tracked)
|
|
404
|
-
assert.equal(spawnSync('git', ['add', '--', artifact], { cwd: workspace }).status, 0);
|
|
412
|
+
assert.equal(spawnSync('git', ['add', '--', artifact], { cwd: workspace, windowsHide: true }).status, 0);
|
|
405
413
|
return fixture.providerResult;
|
|
406
414
|
} });
|
|
407
415
|
assert.equal(receipt.status, 'completed');
|
|
@@ -482,10 +490,10 @@ test('signed task runs only a registered command in a relay-owned worktree and d
|
|
|
482
490
|
const root = await mkdtemp(resolve(tmpdir(), 'dharma-task-runner-'));
|
|
483
491
|
const workspace = resolve(root, 'workspace');
|
|
484
492
|
await mkdir(workspace);
|
|
485
|
-
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace }).status, 0);
|
|
486
|
-
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace }).status, 0);
|
|
487
|
-
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace }).status, 0);
|
|
488
|
-
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace }).status, 0);
|
|
493
|
+
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
494
|
+
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
495
|
+
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
496
|
+
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
489
497
|
const policy = {
|
|
490
498
|
schema: 'dharma.organization-policy/v1', organizationId: 'org_test', revision: '1',
|
|
491
499
|
evidence: { defaultMode: 'deep', registeredWorkspaceOnly: true, excludePaths: [], maximumCapsuleBytes: 1, maximumDailyUploadBytes: 1, maximumExpansionBytes: 1 },
|
|
@@ -550,10 +558,10 @@ test('Claude tasks read required skills from installed files because safe mode d
|
|
|
550
558
|
const root = await mkdtemp(resolve(tmpdir(), 'dharma-task-skill-file-'));
|
|
551
559
|
const workspace = resolve(root, 'workspace');
|
|
552
560
|
await mkdir(workspace);
|
|
553
|
-
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace }).status, 0);
|
|
554
|
-
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace }).status, 0);
|
|
555
|
-
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace }).status, 0);
|
|
556
|
-
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace }).status, 0);
|
|
561
|
+
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
562
|
+
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
563
|
+
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
564
|
+
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
557
565
|
const policy = {
|
|
558
566
|
schema: 'dharma.organization-policy/v1', organizationId: 'org_test', revision: '1',
|
|
559
567
|
evidence: { defaultMode: 'deep', registeredWorkspaceOnly: true, excludePaths: [], maximumCapsuleBytes: 1, maximumDailyUploadBytes: 1, maximumExpansionBytes: 1 },
|
|
@@ -606,10 +614,10 @@ test('read-only signed tasks receive only matching verified knowledge and remove
|
|
|
606
614
|
const root = await mkdtemp(resolve(tmpdir(), 'dharma-task-knowledge-'));
|
|
607
615
|
const workspace = resolve(root, 'workspace');
|
|
608
616
|
await mkdir(workspace);
|
|
609
|
-
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace }).status, 0);
|
|
610
|
-
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace }).status, 0);
|
|
611
|
-
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace }).status, 0);
|
|
612
|
-
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace }).status, 0);
|
|
617
|
+
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
618
|
+
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
619
|
+
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
620
|
+
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
613
621
|
const policy = {
|
|
614
622
|
schema: 'dharma.organization-policy/v1', organizationId: 'org_test', revision: '1',
|
|
615
623
|
evidence: { defaultMode: 'deep', registeredWorkspaceOnly: true, excludePaths: [], maximumCapsuleBytes: 1, maximumDailyUploadBytes: 1, maximumExpansionBytes: 1 },
|
|
@@ -761,11 +769,11 @@ test('provider changes outside signed write paths fail even when untracked or co
|
|
|
761
769
|
await mkdir(resolve(workspace, 'src'), { recursive: true });
|
|
762
770
|
await writeFile(resolve(workspace, 'src', 'allowed.ts'), 'export const allowed = true;\n');
|
|
763
771
|
await writeFile(resolve(workspace, 'outside.txt'), 'protected\n');
|
|
764
|
-
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace }).status, 0);
|
|
765
|
-
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace }).status, 0);
|
|
766
|
-
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace }).status, 0);
|
|
767
|
-
assert.equal(spawnSync('git', ['add', '.'], { cwd: workspace }).status, 0);
|
|
768
|
-
assert.equal(spawnSync('git', ['commit', '-qm', 'initial'], { cwd: workspace }).status, 0);
|
|
772
|
+
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
773
|
+
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
774
|
+
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
775
|
+
assert.equal(spawnSync('git', ['add', '.'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
776
|
+
assert.equal(spawnSync('git', ['commit', '-qm', 'initial'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
769
777
|
const policy = {
|
|
770
778
|
schema: 'dharma.organization-policy/v1', organizationId: 'org_test', revision: '1',
|
|
771
779
|
evidence: { defaultMode: 'deep', registeredWorkspaceOnly: true, excludePaths: [], maximumCapsuleBytes: 1, maximumDailyUploadBytes: 1, maximumExpansionBytes: 1 },
|
|
@@ -805,8 +813,8 @@ test('provider changes outside signed write paths fail even when untracked or co
|
|
|
805
813
|
serverPublicKey: publicKey, receiptStore: new FileTaskReceiptStore(resolve(root, 'committed-receipts')),
|
|
806
814
|
providerExecutor: async ({ workspace: worktree }) => {
|
|
807
815
|
await writeFile(resolve(worktree, 'outside.txt'), 'changed outside scope\n');
|
|
808
|
-
assert.equal(spawnSync('git', ['add', 'outside.txt'], { cwd: worktree }).status, 0);
|
|
809
|
-
assert.equal(spawnSync('git', ['commit', '-qm', 'unauthorized change'], { cwd: worktree }).status, 0);
|
|
816
|
+
assert.equal(spawnSync('git', ['add', 'outside.txt'], { cwd: worktree, windowsHide: true }).status, 0);
|
|
817
|
+
assert.equal(spawnSync('git', ['commit', '-qm', 'unauthorized change'], { cwd: worktree, windowsHide: true }).status, 0);
|
|
810
818
|
return providerResult;
|
|
811
819
|
},
|
|
812
820
|
});
|
|
@@ -907,10 +915,10 @@ test('receipt-required task fails closed before provider execution without an em
|
|
|
907
915
|
const root = await mkdtemp(resolve(tmpdir(), 'dharma-action-decision-'));
|
|
908
916
|
const workspace = resolve(root, 'workspace');
|
|
909
917
|
await mkdir(workspace);
|
|
910
|
-
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace }).status, 0);
|
|
911
|
-
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace }).status, 0);
|
|
912
|
-
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace }).status, 0);
|
|
913
|
-
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace }).status, 0);
|
|
918
|
+
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
919
|
+
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
920
|
+
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
921
|
+
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
914
922
|
const policy = {
|
|
915
923
|
schema: 'dharma.organization-policy/v1', organizationId: 'org_test', revision: '1',
|
|
916
924
|
evidence: { defaultMode: 'deep', registeredWorkspaceOnly: true, excludePaths: [], maximumCapsuleBytes: 1, maximumDailyUploadBytes: 1, maximumExpansionBytes: 1 },
|
|
@@ -944,10 +952,10 @@ test('receipt-required task executes only a KMS-signed release and acknowledges
|
|
|
944
952
|
const root = await mkdtemp(resolve(tmpdir(), 'dharma-action-release-'));
|
|
945
953
|
const workspace = resolve(root, 'workspace');
|
|
946
954
|
await mkdir(workspace);
|
|
947
|
-
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace }).status, 0);
|
|
948
|
-
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace }).status, 0);
|
|
949
|
-
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace }).status, 0);
|
|
950
|
-
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace }).status, 0);
|
|
955
|
+
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
956
|
+
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
957
|
+
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
958
|
+
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
951
959
|
const policy = {
|
|
952
960
|
schema: 'dharma.organization-policy/v1', organizationId: 'org_test', revision: '1',
|
|
953
961
|
evidence: { defaultMode: 'deep', registeredWorkspaceOnly: true, excludePaths: [], maximumCapsuleBytes: 1, maximumDailyUploadBytes: 1, maximumExpansionBytes: 1 },
|
|
@@ -1175,10 +1183,10 @@ for (const outcome of ['block', 'escalate', 'withhold']) {
|
|
|
1175
1183
|
await mkdir(workspace);
|
|
1176
1184
|
const protectedPath = resolve(workspace, 'protected.txt');
|
|
1177
1185
|
await writeFile(protectedPath, 'original protected content\n');
|
|
1178
|
-
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace }).status, 0);
|
|
1179
|
-
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace }).status, 0);
|
|
1180
|
-
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace }).status, 0);
|
|
1181
|
-
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace }).status, 0);
|
|
1186
|
+
assert.equal(spawnSync('git', ['init', '-q'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
1187
|
+
assert.equal(spawnSync('git', ['config', 'user.email', 'test@dharma-ai.io'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
1188
|
+
assert.equal(spawnSync('git', ['config', 'user.name', 'Dharma Test'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
1189
|
+
assert.equal(spawnSync('git', ['commit', '--allow-empty', '-qm', 'initial'], { cwd: workspace, windowsHide: true }).status, 0);
|
|
1182
1190
|
const policy = {
|
|
1183
1191
|
schema: 'dharma.organization-policy/v1', organizationId: 'org_test', revision: '1',
|
|
1184
1192
|
evidence: { defaultMode: 'deep', registeredWorkspaceOnly: true, excludePaths: [], maximumCapsuleBytes: 1, maximumDailyUploadBytes: 1, maximumExpansionBytes: 1 },
|
|
@@ -1217,4 +1225,296 @@ for (const outcome of ['block', 'escalate', 'withhold']) {
|
|
|
1217
1225
|
assert.equal(await readFile(protectedPath, 'utf8'), 'original protected content\n');
|
|
1218
1226
|
});
|
|
1219
1227
|
}
|
|
1228
|
+
function acceptanceEnvironment(input) {
|
|
1229
|
+
const builder = Reflect.get(taskRunner, 'acceptanceCommandEnvironment');
|
|
1230
|
+
assert.equal(typeof builder, 'function', 'acceptance commands need an explicit environment builder');
|
|
1231
|
+
return builder(input);
|
|
1232
|
+
}
|
|
1233
|
+
const ENVIRONMENT_PROBE = 'process.stdout.write(JSON.stringify(process.env))';
|
|
1234
|
+
const RUNNER_OWNED_NAMES = ['DHARMA_TASK_WORKTREE', 'DHARMA_EXTERNAL_IDEMPOTENCY_KEY', 'DHARMA_ACTION_DIGEST'];
|
|
1235
|
+
const SYNTHETIC_DIGEST = `sha256:${'c'.repeat(64)}`;
|
|
1236
|
+
async function withParentEnvironment(values, run) {
|
|
1237
|
+
const previous = new Map(Object.keys(values).map((name) => [name, process.env[name]]));
|
|
1238
|
+
Object.assign(process.env, values);
|
|
1239
|
+
try {
|
|
1240
|
+
return await run();
|
|
1241
|
+
}
|
|
1242
|
+
finally {
|
|
1243
|
+
for (const [name, value] of previous) {
|
|
1244
|
+
if (value === undefined)
|
|
1245
|
+
delete process.env[name];
|
|
1246
|
+
else
|
|
1247
|
+
process.env[name] = value;
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
function environmentValue(environment, name) {
|
|
1252
|
+
if (process.platform !== 'win32')
|
|
1253
|
+
return environment[name];
|
|
1254
|
+
const key = Object.keys(environment).find((candidate) => candidate.toUpperCase() === name.toUpperCase());
|
|
1255
|
+
return key === undefined ? undefined : environment[key];
|
|
1256
|
+
}
|
|
1257
|
+
function probeCommand(inherit) {
|
|
1258
|
+
return {
|
|
1259
|
+
argv: [process.execPath, '-e', ENVIRONMENT_PROBE], timeoutSeconds: 10,
|
|
1260
|
+
...(inherit ? { ...{ environment: { inherit } } } : {}),
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
test('acceptance commands run with an explicit environment instead of the relay process environment', async (t) => {
|
|
1264
|
+
const fixture = await requiredArtifactFixture(t, []);
|
|
1265
|
+
fixture.policy.tasks.allowedCommands.permitted = probeCommand(['ACCEPTANCE_PERMITTED_INPUT']);
|
|
1266
|
+
fixture.policy.tasks.allowedCommands.plain = probeCommand();
|
|
1267
|
+
for (const commandId of ['permitted', 'plain']) {
|
|
1268
|
+
fixture.unsigned.authority.commands.push({ commandId });
|
|
1269
|
+
fixture.unsigned.acceptance.commands.push({ commandId });
|
|
1270
|
+
}
|
|
1271
|
+
let worktree = '';
|
|
1272
|
+
const receipt = await withParentEnvironment({
|
|
1273
|
+
ACCEPTANCE_PARENT_SENTINEL: 'synthetic-parent-sentinel',
|
|
1274
|
+
SYNTHETIC_SERVICE_TOKEN: 'synthetic-token-value',
|
|
1275
|
+
ACCEPTANCE_PERMITTED_INPUT: 'synthetic-permitted-value',
|
|
1276
|
+
DHARMA_TASK_WORKTREE: 'synthetic-forged-worktree',
|
|
1277
|
+
DHARMA_EXTERNAL_IDEMPOTENCY_KEY: 'synthetic-forged-key',
|
|
1278
|
+
DHARMA_ACTION_DIGEST: 'synthetic-forged-digest',
|
|
1279
|
+
}, () => executeTask({ ...fixture.input, task: fixture.signed(),
|
|
1280
|
+
providerExecutor: async ({ workspace }) => { worktree = workspace; return fixture.providerResult; } }));
|
|
1281
|
+
assert.equal(receipt.status, 'completed', receipt.commandResults.at(-1)?.stderr);
|
|
1282
|
+
const permitted = JSON.parse(receipt.commandResults[1].stdout);
|
|
1283
|
+
const plain = JSON.parse(receipt.commandResults[2].stdout);
|
|
1284
|
+
for (const environment of [permitted, plain]) {
|
|
1285
|
+
assert.equal(environmentValue(environment, 'ACCEPTANCE_PARENT_SENTINEL'), undefined);
|
|
1286
|
+
assert.equal(environmentValue(environment, 'SYNTHETIC_SERVICE_TOKEN'), undefined);
|
|
1287
|
+
assert.deepEqual(Object.keys(environment).filter((name) => /^npm_/i.test(name)), []);
|
|
1288
|
+
assert.equal(environmentValue(environment, 'DHARMA_TASK_WORKTREE'), worktree);
|
|
1289
|
+
assert.equal(environmentValue(environment, 'DHARMA_EXTERNAL_IDEMPOTENCY_KEY'), undefined);
|
|
1290
|
+
assert.equal(environmentValue(environment, 'DHARMA_ACTION_DIGEST'), undefined);
|
|
1291
|
+
const essentials = process.platform === 'win32'
|
|
1292
|
+
? ['PATH', 'PATHEXT', 'SystemRoot', 'ComSpec', 'TEMP', 'USERPROFILE']
|
|
1293
|
+
: ['PATH', 'HOME', 'TMPDIR', 'LANG'];
|
|
1294
|
+
for (const name of essentials) {
|
|
1295
|
+
assert.equal(environmentValue(environment, name), environmentValue(process.env, name), name);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
assert.equal(environmentValue(permitted, 'ACCEPTANCE_PERMITTED_INPUT'), 'synthetic-permitted-value');
|
|
1299
|
+
assert.equal(environmentValue(plain, 'ACCEPTANCE_PERMITTED_INPUT'), undefined);
|
|
1300
|
+
});
|
|
1301
|
+
test('relay Git checks after an acceptance command do not run a Git monitor hook the command configured', async (t) => {
|
|
1302
|
+
const fixture = await requiredArtifactFixture(t, []);
|
|
1303
|
+
const marker = resolve(fixture.root, 'monitor-hook-ran.json');
|
|
1304
|
+
const hook = resolve(fixture.root, 'monitor-hook.cjs');
|
|
1305
|
+
await writeFile(hook, [
|
|
1306
|
+
'require("node:fs").writeFileSync(',
|
|
1307
|
+
` ${JSON.stringify(marker)},`,
|
|
1308
|
+
' JSON.stringify({ sentinel: process.env.ACCEPTANCE_PARENT_SENTINEL ?? null }));',
|
|
1309
|
+
'process.exit(1);',
|
|
1310
|
+
].join('\n'));
|
|
1311
|
+
const shellPath = (path) => `'${path.replace(/\\/g, '/')}'`;
|
|
1312
|
+
fixture.policy.tasks.allowedCommands.configure = {
|
|
1313
|
+
argv: ['git', 'config', 'core.fsmonitor', `${shellPath(process.execPath)} ${shellPath(hook)}`],
|
|
1314
|
+
timeoutSeconds: 10,
|
|
1315
|
+
};
|
|
1316
|
+
fixture.unsigned.authority.commands.push({ commandId: 'configure' });
|
|
1317
|
+
fixture.unsigned.acceptance.commands.push({ commandId: 'configure' });
|
|
1318
|
+
const receipt = await withParentEnvironment({ ACCEPTANCE_PARENT_SENTINEL: 'synthetic-parent-sentinel' }, () => executeTask({ ...fixture.input, task: fixture.signed(), providerExecutor: async () => fixture.providerResult }));
|
|
1319
|
+
assert.equal(receipt.commandResults[1]?.exitCode, 0, receipt.commandResults[1]?.stderr);
|
|
1320
|
+
const hookOutput = await readFile(marker, 'utf8').catch(() => undefined);
|
|
1321
|
+
assert.equal(hookOutput, undefined, 'relay Git ran the monitor hook');
|
|
1322
|
+
assert.equal(receipt.status, 'completed', receipt.commandResults.at(-1)?.stderr);
|
|
1323
|
+
});
|
|
1324
|
+
test('acceptance command policy cannot inherit runner-owned environment names', async (t) => {
|
|
1325
|
+
for (const name of [...RUNNER_OWNED_NAMES, 'dharma_action_digest']) {
|
|
1326
|
+
await t.test(name, async (child) => {
|
|
1327
|
+
const fixture = await requiredArtifactFixture(child, []);
|
|
1328
|
+
fixture.policy.tasks.allowedCommands.probe = probeCommand([name]);
|
|
1329
|
+
fixture.unsigned.authority.commands.push({ commandId: 'probe' });
|
|
1330
|
+
fixture.unsigned.acceptance.commands.push({ commandId: 'probe' });
|
|
1331
|
+
let providerCalls = 0;
|
|
1332
|
+
const receipt = await withParentEnvironment({ [name]: 'synthetic-forged-value' }, () => executeTask({
|
|
1333
|
+
...fixture.input, task: fixture.signed(),
|
|
1334
|
+
providerExecutor: async () => { providerCalls += 1; return fixture.providerResult; }
|
|
1335
|
+
}));
|
|
1336
|
+
assert.equal(receipt.status, 'failed');
|
|
1337
|
+
assert.equal(providerCalls, 0);
|
|
1338
|
+
assert.equal(receipt.commandResults.some(({ commandId }) => commandId === 'probe'), false);
|
|
1339
|
+
assert.match(receipt.commandResults.at(-1)?.stderr || '', /environment/);
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
});
|
|
1343
|
+
test('signed tasks cannot carry their own acceptance-command environment', async (t) => {
|
|
1344
|
+
const fixture = await requiredArtifactFixture(t, []);
|
|
1345
|
+
fixture.policy.tasks.allowedCommands.probe = probeCommand();
|
|
1346
|
+
fixture.unsigned.authority.commands.push({ commandId: 'probe' });
|
|
1347
|
+
for (const acceptance of [
|
|
1348
|
+
{ commands: [{ commandId: 'probe', environment: { DHARMA_TASK_WORKTREE: 'forged' } }], requiredArtifacts: [] },
|
|
1349
|
+
{ commands: [{ commandId: 'probe' }], requiredArtifacts: [], environment: { DHARMA_ACTION_DIGEST: 'forged' } },
|
|
1350
|
+
]) {
|
|
1351
|
+
const task = fixture.signed({ acceptance });
|
|
1352
|
+
assert.throws(() => verifyTaskEnvelope(task, fixture.publicKey), /schema validation/);
|
|
1353
|
+
let providerCalls = 0;
|
|
1354
|
+
await assert.rejects(executeTask({ ...fixture.input, task,
|
|
1355
|
+
providerExecutor: async () => { providerCalls += 1; return fixture.providerResult; } }));
|
|
1356
|
+
assert.equal(providerCalls, 0);
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
test('decision-bound acceptance variables come only from the verified decision receipt', async () => {
|
|
1360
|
+
const root = await mkdtemp(resolve(tmpdir(), 'dharma-acceptance-decision-'));
|
|
1361
|
+
try {
|
|
1362
|
+
const workspace = resolve(root, 'workspace');
|
|
1363
|
+
await mkdir(workspace);
|
|
1364
|
+
for (const argv of [['init', '-q'], ['config', 'user.email', 'test@dharma-ai.io'],
|
|
1365
|
+
['config', 'user.name', 'Dharma Test'], ['commit', '--allow-empty', '-qm', 'initial']]) {
|
|
1366
|
+
assert.equal(spawnSync('git', argv, { cwd: workspace, windowsHide: true }).status, 0);
|
|
1367
|
+
}
|
|
1368
|
+
const policy = {
|
|
1369
|
+
schema: 'dharma.organization-policy/v1', organizationId: 'org_test', revision: '1',
|
|
1370
|
+
evidence: { defaultMode: 'deep', registeredWorkspaceOnly: true, excludePaths: [], maximumCapsuleBytes: 1,
|
|
1371
|
+
maximumDailyUploadBytes: 1, maximumExpansionBytes: 1 },
|
|
1372
|
+
tasks: { defaultNetwork: 'deny', defaultGit: 'task_branch', allowedCommands: { probe: probeCommand() },
|
|
1373
|
+
writePaths: [], requireLocalConfirmationFor: [] },
|
|
1374
|
+
skills: { automaticInstall: true, automaticPromotionMaxRisk: 'R2', canaryPercent: 10 }, retention: {}, budgets: {},
|
|
1375
|
+
};
|
|
1376
|
+
const taskKeys = generateKeyPairSync('ed25519');
|
|
1377
|
+
const decisionKeys = generateKeyPairSync('ed25519');
|
|
1378
|
+
const now = new Date();
|
|
1379
|
+
const baseTask = {
|
|
1380
|
+
schema: 'dharma.task/v1', taskId: randomUUID(), organizationId: 'org_test', workspaceId: 'workspace',
|
|
1381
|
+
taskType: 'external_request',
|
|
1382
|
+
target: { deviceId: 'device', endpointId: randomUUID(), provider: 'codex' },
|
|
1383
|
+
requiredCapabilities: ['action_decision_receipts_v1'],
|
|
1384
|
+
skillBundle: null, instructions: 'Inspect the repository.', requiredSkills: [],
|
|
1385
|
+
authority: { readPaths: ['.'], writePaths: [], commands: [{ commandId: 'probe' }], network: 'deny', git: 'task_branch' },
|
|
1386
|
+
execution: { isolation: 'git_worktree', timeoutSeconds: 120, leaseSeconds: 20, maximumConcurrentAgents: 1 },
|
|
1387
|
+
acceptance: { commands: [{ commandId: 'probe' }], requiredArtifacts: [] },
|
|
1388
|
+
budget: { mode: 'byok_local', maximumDharmaCostCents: 0 },
|
|
1389
|
+
createdAt: now.toISOString(), expiresAt: new Date(now.getTime() + 60_000).toISOString(), nonce: randomUUID(),
|
|
1390
|
+
};
|
|
1391
|
+
const actionDecision = embedDecision(baseTask, 'release', decisionKeys.privateKey, now);
|
|
1392
|
+
const unsigned = { ...baseTask, actionDecision };
|
|
1393
|
+
const task = { ...unsigned, signature: signCanonicalObject(unsigned, taskKeys.privateKey) };
|
|
1394
|
+
let providerInput;
|
|
1395
|
+
const receipt = await withParentEnvironment({
|
|
1396
|
+
DHARMA_EXTERNAL_IDEMPOTENCY_KEY: 'synthetic-forged-key',
|
|
1397
|
+
DHARMA_ACTION_DIGEST: 'synthetic-forged-digest',
|
|
1398
|
+
DHARMA_TASK_WORKTREE: 'synthetic-forged-worktree',
|
|
1399
|
+
}, () => executeTask({
|
|
1400
|
+
task, policy, workspace, relayStateDirectory: resolve(root, 'state'), serverPublicKey: taskKeys.publicKey,
|
|
1401
|
+
receiptStore: new FileTaskReceiptStore(resolve(root, 'receipts')),
|
|
1402
|
+
actionDecisions: { resolvePublicKey: () => decisionKeys.publicKey },
|
|
1403
|
+
providerExecutor: async (input) => {
|
|
1404
|
+
providerInput = input;
|
|
1405
|
+
return { provider: 'codex', exitCode: 0, signal: null, timedOut: false, stdout: 'done', stderr: '',
|
|
1406
|
+
stdoutSha256: `sha256:${'1'.repeat(64)}`, stderrSha256: `sha256:${'0'.repeat(64)}` };
|
|
1407
|
+
},
|
|
1408
|
+
}));
|
|
1409
|
+
assert.equal(receipt.status, 'completed', receipt.commandResults.at(-1)?.stderr);
|
|
1410
|
+
assert.equal(providerInput?.externalIdempotencyKey, actionDecision.id);
|
|
1411
|
+
assert.equal(providerInput?.actionDigest, actionDecision.actionDigest);
|
|
1412
|
+
const environment = JSON.parse(receipt.commandResults[1].stdout);
|
|
1413
|
+
assert.equal(environmentValue(environment, 'DHARMA_EXTERNAL_IDEMPOTENCY_KEY'), actionDecision.id);
|
|
1414
|
+
assert.equal(environmentValue(environment, 'DHARMA_ACTION_DIGEST'), actionDecision.actionDigest);
|
|
1415
|
+
assert.equal(environmentValue(environment, 'DHARMA_TASK_WORKTREE'), providerInput?.workspace);
|
|
1416
|
+
}
|
|
1417
|
+
finally {
|
|
1418
|
+
await rm(root, { recursive: true, force: true });
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
test('acceptance environment builder copies only POSIX essentials, permitted names and runner-owned values', () => {
|
|
1422
|
+
const source = {
|
|
1423
|
+
PATH: '/usr/local/bin:/usr/bin', HOME: '/home/customer', TMPDIR: '/tmp/customer', LANG: 'C.UTF-8',
|
|
1424
|
+
LANGUAGE: 'en', LC_ALL: 'C.UTF-8', LC_CTYPE: 'C.UTF-8', LC_MESSAGES: 'C', LC_COLLATE: 'C', LC_NUMERIC: 'C',
|
|
1425
|
+
LC_TIME: 'C', LC_MONETARY: 'C', TZ: 'UTC', USER: 'customer', LOGNAME: 'customer',
|
|
1426
|
+
XDG_CONFIG_HOME: '/home/customer/.config', XDG_CACHE_HOME: '/home/customer/.cache',
|
|
1427
|
+
HTTPS_PROXY: 'http://proxy.example.test:3128',
|
|
1428
|
+
XDG_RUNTIME_DIR: '/run/user/1000', DBUS_SESSION_BUS_ADDRESS: 'unix:path=/run/user/1000/bus',
|
|
1429
|
+
SSH_AUTH_SOCK: '/tmp/agent.sock', GPG_AGENT_INFO: '/tmp/gpg', WSL_INTEROP: '/run/WSL/1_interop', WSLENV: 'X',
|
|
1430
|
+
DISPLAY: ':0', WAYLAND_DISPLAY: 'wayland-0', CODEX_HOME: '/home/customer/.codex',
|
|
1431
|
+
CLAUDE_CONFIG_DIR: '/home/customer/.claude', SHELL: '/bin/bash', TERM: 'xterm', INVOCATION_ID: 'synthetic',
|
|
1432
|
+
JOURNAL_STREAM: '8:1', MANAGERPID: '1', npm_config_userconfig: '/home/customer/.npmrc', npm_lifecycle_event: 'test',
|
|
1433
|
+
XPC_SERVICE_NAME: 'synthetic', XPC_FLAGS: '0x0', __CF_USER_TEXT_ENCODING: '0x1F5:0x0:0x0',
|
|
1434
|
+
DHARMA_HOME: '/home/customer/.dharma', DHARMA_ORG_API_TOKEN: 'synthetic-token', DHARMA_VAULT_KEY: 'synthetic-key',
|
|
1435
|
+
DHARMA_TASK_WORKTREE: '/forged', DHARMA_EXTERNAL_IDEMPOTENCY_KEY: 'forged-key', DHARMA_ACTION_DIGEST: 'forged-digest',
|
|
1436
|
+
ACCEPTANCE_PARENT_SENTINEL: 'synthetic-parent-sentinel', path: '/lowercase-is-a-different-name',
|
|
1437
|
+
};
|
|
1438
|
+
const essentials = {
|
|
1439
|
+
PATH: source.PATH, HOME: source.HOME, TMPDIR: source.TMPDIR, LANG: source.LANG, LANGUAGE: source.LANGUAGE,
|
|
1440
|
+
LC_ALL: source.LC_ALL, LC_CTYPE: source.LC_CTYPE, LC_MESSAGES: source.LC_MESSAGES, LC_COLLATE: source.LC_COLLATE,
|
|
1441
|
+
LC_NUMERIC: source.LC_NUMERIC, LC_TIME: source.LC_TIME, LC_MONETARY: source.LC_MONETARY, TZ: source.TZ,
|
|
1442
|
+
USER: source.USER, LOGNAME: source.LOGNAME, XDG_CONFIG_HOME: source.XDG_CONFIG_HOME,
|
|
1443
|
+
XDG_CACHE_HOME: source.XDG_CACHE_HOME,
|
|
1444
|
+
};
|
|
1445
|
+
for (const platform of ['linux', 'darwin']) {
|
|
1446
|
+
assert.deepEqual(acceptanceEnvironment({ source, platform, cwd: '/work/tree', command: probeCommand() }), { ...essentials, DHARMA_TASK_WORKTREE: '/work/tree' }, platform);
|
|
1447
|
+
assert.deepEqual(acceptanceEnvironment({ source, platform, cwd: '/work/tree',
|
|
1448
|
+
command: probeCommand(['HTTPS_PROXY', 'NOT_PRESENT']),
|
|
1449
|
+
actionDecision: { externalIdempotencyKey: 'decision-id', actionDigest: SYNTHETIC_DIGEST } }), {
|
|
1450
|
+
...essentials, HTTPS_PROXY: source.HTTPS_PROXY, DHARMA_TASK_WORKTREE: '/work/tree',
|
|
1451
|
+
DHARMA_EXTERNAL_IDEMPOTENCY_KEY: 'decision-id', DHARMA_ACTION_DIGEST: SYNTHETIC_DIGEST,
|
|
1452
|
+
}, platform);
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
test('acceptance command environment policy is bounded and cannot name runner-owned variables', () => {
|
|
1456
|
+
const source = { HTTPS_PROXY: 'http://proxy.example.test:3128', NODE_EXTRA_CA_CERTS: '/etc/ssl/synthetic.pem' };
|
|
1457
|
+
const command = (environment) => ({ argv: [process.execPath], timeoutSeconds: 10, environment });
|
|
1458
|
+
assert.deepEqual(acceptanceEnvironment({ source, platform: 'linux', cwd: '/work',
|
|
1459
|
+
command: command({ inherit: ['HTTPS_PROXY', 'NODE_EXTRA_CA_CERTS'] }) }), { ...source, DHARMA_TASK_WORKTREE: '/work' });
|
|
1460
|
+
assert.deepEqual(acceptanceEnvironment({ source, platform: 'linux', cwd: '/work', command: command({ inherit: [] }) }), { DHARMA_TASK_WORKTREE: '/work' });
|
|
1461
|
+
const invalid = [
|
|
1462
|
+
{ inherit: ['DHARMA_TASK_WORKTREE'] },
|
|
1463
|
+
{ inherit: ['DHARMA_EXTERNAL_IDEMPOTENCY_KEY'] },
|
|
1464
|
+
{ inherit: ['DHARMA_ACTION_DIGEST'] },
|
|
1465
|
+
{ inherit: ['dharma_action_digest'] },
|
|
1466
|
+
{ inherit: ['Dharma_Task_Worktree'] },
|
|
1467
|
+
{ inherit: ['DHARMA_HOME'] },
|
|
1468
|
+
{ inherit: ['1INVALID'] },
|
|
1469
|
+
{ inherit: ['NAME=VALUE'] },
|
|
1470
|
+
{ inherit: [''] },
|
|
1471
|
+
{ inherit: ['A'.repeat(129)] },
|
|
1472
|
+
{ inherit: ['HTTPS_PROXY', 'https_proxy'] },
|
|
1473
|
+
{ inherit: Array.from({ length: 33 }, (_, index) => `NAME_${index}`) },
|
|
1474
|
+
{ inherit: 'HTTPS_PROXY' },
|
|
1475
|
+
{ inherit: [42] },
|
|
1476
|
+
{ inherit: ['HTTPS_PROXY'], values: { HTTPS_PROXY: 'http://proxy.example.test' } },
|
|
1477
|
+
{},
|
|
1478
|
+
null,
|
|
1479
|
+
['HTTPS_PROXY'],
|
|
1480
|
+
];
|
|
1481
|
+
for (const environment of invalid) {
|
|
1482
|
+
for (const platform of ['linux', 'win32']) {
|
|
1483
|
+
assert.throws(() => acceptanceEnvironment({ source, platform, cwd: '/work', command: command(environment) }), /environment/, `${platform} ${JSON.stringify(environment)}`);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
});
|
|
1487
|
+
test('acceptance environment builder handles Windows essentials and case-insensitive names', () => {
|
|
1488
|
+
const source = {
|
|
1489
|
+
Path: 'C:\\Windows\\system32;C:\\Program Files\\nodejs', PATHEXT: '.COM;.EXE;.BAT;.CMD',
|
|
1490
|
+
SystemRoot: 'C:\\Windows', windir: 'C:\\Windows', ComSpec: 'C:\\Windows\\system32\\cmd.exe', SystemDrive: 'C:',
|
|
1491
|
+
TEMP: 'C:\\Users\\customer\\AppData\\Local\\Temp', TMP: 'C:\\Users\\customer\\AppData\\Local\\Temp',
|
|
1492
|
+
USERPROFILE: 'C:\\Users\\customer', APPDATA: 'C:\\Users\\customer\\AppData\\Roaming',
|
|
1493
|
+
LOCALAPPDATA: 'C:\\Users\\customer\\AppData\\Local', ProgramFiles: 'C:\\Program Files',
|
|
1494
|
+
'ProgramFiles(x86)': 'C:\\Program Files (x86)', ProgramW6432: 'C:\\Program Files', ProgramData: 'C:\\ProgramData',
|
|
1495
|
+
CommonProgramFiles: 'C:\\Program Files\\Common Files', NUMBER_OF_PROCESSORS: '8', PROCESSOR_ARCHITECTURE: 'AMD64',
|
|
1496
|
+
OS: 'Windows_NT', https_proxy: 'http://proxy.example.test:3128',
|
|
1497
|
+
HOMEDRIVE: 'C:', HOMEPATH: '\\Users\\customer', USERNAME: 'customer', USERDOMAIN: 'DOMAIN',
|
|
1498
|
+
COMPUTERNAME: 'HOST', PSModulePath: 'C:\\modules', npm_config_cache: 'C:\\npm-cache',
|
|
1499
|
+
Dharma_Task_Worktree: 'C:\\forged', dharma_action_digest: 'forged-digest', DHARMA_ORG_API_TOKEN: 'synthetic-token',
|
|
1500
|
+
ACCEPTANCE_PARENT_SENTINEL: 'synthetic-parent-sentinel',
|
|
1501
|
+
};
|
|
1502
|
+
const { https_proxy: _proxy, HOMEDRIVE: _drive, HOMEPATH: _homePath, USERNAME: _user, USERDOMAIN: _domain, COMPUTERNAME: _computer, PSModulePath: _modules, npm_config_cache: _npm, Dharma_Task_Worktree: _worktree, dharma_action_digest: _digest, DHARMA_ORG_API_TOKEN: _token, ACCEPTANCE_PARENT_SENTINEL: _sentinel, ...essentials } = source;
|
|
1503
|
+
const environment = acceptanceEnvironment({ source, platform: 'win32', cwd: 'C:\\work\\tree',
|
|
1504
|
+
command: probeCommand(['HTTPS_PROXY']) });
|
|
1505
|
+
assert.deepEqual(environment, { ...essentials, https_proxy: source.https_proxy, DHARMA_TASK_WORKTREE: 'C:\\work\\tree' });
|
|
1506
|
+
assert.equal(Object.keys(environment).filter((name) => name.toUpperCase() === 'PATH').length, 1);
|
|
1507
|
+
assert.equal(Object.keys(environment).filter((name) => name.toUpperCase().startsWith('DHARMA_')).length, 1);
|
|
1508
|
+
assert.deepEqual(acceptanceEnvironment({ source: { PATH: 'C:\\Windows', SYSTEMROOT: 'C:\\Windows' }, platform: 'win32',
|
|
1509
|
+
cwd: 'C:\\work', command: probeCommand(),
|
|
1510
|
+
actionDecision: { externalIdempotencyKey: 'decision-id', actionDigest: SYNTHETIC_DIGEST } }), {
|
|
1511
|
+
PATH: 'C:\\Windows', SYSTEMROOT: 'C:\\Windows', DHARMA_TASK_WORKTREE: 'C:\\work',
|
|
1512
|
+
DHARMA_EXTERNAL_IDEMPOTENCY_KEY: 'decision-id', DHARMA_ACTION_DIGEST: SYNTHETIC_DIGEST,
|
|
1513
|
+
});
|
|
1514
|
+
for (const name of [...RUNNER_OWNED_NAMES, 'dharma_task_worktree', 'DHARMA_HOME']) {
|
|
1515
|
+
for (const platform of ['win32', 'linux']) {
|
|
1516
|
+
assert.throws(() => acceptanceEnvironment({ source, platform, cwd: 'C:\\work', command: probeCommand([name]) }), /environment/, `${platform} ${name}`);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
});
|
|
1220
1520
|
//# sourceMappingURL=index.test.js.map
|