-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathdcode-base-image-runtime-evidence.test.ts
More file actions
282 lines (261 loc) · 8.83 KB
/
Copy pathdcode-base-image-runtime-evidence.test.ts
File metadata and controls
282 lines (261 loc) · 8.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
import { describe, expect, it } from "vitest";
import type { SandboxBaseImageResolutionMetadata } from "../../../src/lib/sandbox-base-image/types.ts";
import { DCODE_BASE_IMAGE, DCODE_BASE_IMAGE_ENV } from "../fixtures/dcode-base-image.ts";
import {
DCODE_BASE_IMAGE_TARGET_ID,
dcodeBaseImageReferenceForContract,
loadDcodeBaseImagePublicationEvidence,
parseDcodeBaseImagePublicationEvidence,
verifyDcodeBaseImageRuntimeEvidence,
} from "../live/dcode-base-image-runtime-evidence.ts";
const INDEX_DIGEST = `sha256:${"a".repeat(64)}`;
const AMD64_DIGEST = `sha256:${"b".repeat(64)}`;
const ARM64_DIGEST = `sha256:${"c".repeat(64)}`;
const INDEX_REFERENCE = `${DCODE_BASE_IMAGE}@${INDEX_DIGEST}`;
const AMD64_REFERENCE = `${DCODE_BASE_IMAGE}@${AMD64_DIGEST}`;
const ARM64_REFERENCE = `${DCODE_BASE_IMAGE}@${ARM64_DIGEST}`;
const CANDIDATE_REVISION = "d".repeat(40);
const PUBLICATION_REVISION = "e".repeat(40);
function publicationEnvironment(overrides: NodeJS.ProcessEnv = {}): NodeJS.ProcessEnv {
return {
[DCODE_BASE_IMAGE_ENV]: AMD64_REFERENCE,
...overrides,
};
}
function publicationEvidence() {
return {
contractVersion: 1,
candidateSha: CANDIDATE_REVISION,
base: {
agent: "langchain-deepagents-code",
contractVersion: 1,
digest: INDEX_DIGEST,
image: DCODE_BASE_IMAGE,
platformDigests: {
"linux/amd64": AMD64_DIGEST,
"linux/arm64": ARM64_DIGEST,
},
platformReferences: {
"linux/amd64": AMD64_REFERENCE,
"linux/arm64": ARM64_REFERENCE,
},
platforms: ["linux/amd64", "linux/arm64"],
reference: INDEX_REFERENCE,
run: { attempt: 1, id: 1234 },
sourceRevision: PUBLICATION_REVISION,
},
};
}
function resolutionMetadata(
overrides: Partial<SandboxBaseImageResolutionMetadata> = {},
): SandboxBaseImageResolutionMetadata {
return {
schema: 1,
key: "resolution-key",
imageName: DCODE_BASE_IMAGE,
ref: AMD64_REFERENCE,
digest: AMD64_DIGEST,
source: "override",
imageId: `sha256:${"e".repeat(64)}`,
os: "linux",
architecture: "amd64",
glibcVersion: "2.39",
requireOpenshellSandboxAbi: true,
minGlibcVersion: "2.39",
...overrides,
};
}
describe("Deep Agents Code published base runtime evidence", () => {
it("selects the linux/amd64 platform reference when trusted manual PR E2E supplies it", () => {
const environment = publicationEnvironment({
GITHUB_ACTIONS: "true",
GITHUB_EVENT_NAME: "workflow_dispatch",
GITHUB_SHA: "f".repeat(40),
NEMOCLAW_E2E_EXPECTED_SHA: CANDIDATE_REVISION,
});
const contract = parseDcodeBaseImagePublicationEvidence(publicationEvidence(), environment);
expect(dcodeBaseImageReferenceForContract(contract)).toBe(AMD64_REFERENCE);
expect(environment[DCODE_BASE_IMAGE_ENV]).toBe(AMD64_REFERENCE);
});
it("records the completed sandbox image only when its platform digest matches publication", () => {
const contract = parseDcodeBaseImagePublicationEvidence(
publicationEvidence(),
publicationEnvironment(),
);
expect(
verifyDcodeBaseImageRuntimeEvidence(
contract,
"nemoclaw-langchain-deepagents-code:e2e",
resolutionMetadata(),
),
).toEqual({
contractReference: INDEX_REFERENCE,
digest: AMD64_DIGEST,
image: DCODE_BASE_IMAGE,
imageId: `sha256:${"e".repeat(64)}`,
platform: "linux/amd64",
reference: AMD64_REFERENCE,
sandboxImage: "nemoclaw-langchain-deepagents-code:e2e",
source: "override",
sourceRevision: PUBLICATION_REVISION,
});
});
it("rejects the publication index instead of the validated platform reference (#9386)", () => {
expect(() =>
parseDcodeBaseImagePublicationEvidence(
publicationEvidence(),
publicationEnvironment({
[DCODE_BASE_IMAGE_ENV]: INDEX_REFERENCE,
}),
),
).toThrow(/does not match the published linux\/amd64 base contract/);
});
it("prefers the selected manual candidate over the trusted workflow SHA", () => {
expect(
parseDcodeBaseImagePublicationEvidence(
publicationEvidence(),
publicationEnvironment({
GITHUB_ACTIONS: "true",
GITHUB_SHA: "f".repeat(40),
NEMOCLAW_E2E_EXPECTED_SHA: CANDIDATE_REVISION,
}),
),
).toMatchObject({ reference: INDEX_REFERENCE });
});
it("uses the workflow SHA for trusted main qualification", () => {
expect(
parseDcodeBaseImagePublicationEvidence(
publicationEvidence(),
publicationEnvironment({
GITHUB_ACTIONS: "true",
GITHUB_SHA: CANDIDATE_REVISION,
NEMOCLAW_E2E_EXPECTED_SHA: "",
}),
),
).toMatchObject({ reference: INDEX_REFERENCE });
});
it.each([
[
"a manual candidate",
{
GITHUB_ACTIONS: "true",
GITHUB_SHA: CANDIDATE_REVISION,
NEMOCLAW_E2E_EXPECTED_SHA: "f".repeat(40),
},
],
[
"a trusted main candidate",
{
GITHUB_ACTIONS: "true",
GITHUB_SHA: "f".repeat(40),
NEMOCLAW_E2E_EXPECTED_SHA: "",
},
],
])("rejects stale publication evidence for %s", (_label, environment) => {
expect(() =>
parseDcodeBaseImagePublicationEvidence(
publicationEvidence(),
publicationEnvironment(environment),
),
).toThrow(/candidate SHA does not match the selected candidate/);
});
it.each([
["a missing workflow SHA", undefined],
["a malformed workflow SHA", "main"],
])("rejects %s in GitHub Actions", (_label, githubSha) => {
expect(() =>
parseDcodeBaseImagePublicationEvidence(
publicationEvidence(),
publicationEnvironment({
GITHUB_ACTIONS: "true",
GITHUB_SHA: githubSha,
NEMOCLAW_E2E_EXPECTED_SHA: "",
}),
),
).toThrow(/expected candidate SHA is invalid/);
});
it("rejects a platform reference that does not match its published digest", () => {
const evidence = publicationEvidence();
evidence.base.platformReferences["linux/amd64"] = INDEX_REFERENCE;
expect(() =>
parseDcodeBaseImagePublicationEvidence(evidence, publicationEnvironment()),
).toThrow(/base contract linux\/amd64 reference is invalid/);
});
it("allows direct local execution without the workflow-only publication artifact", () => {
expect(
loadDcodeBaseImagePublicationEvidence(
DCODE_BASE_IMAGE_TARGET_ID,
`/missing-dcode-base-evidence-${process.pid}.json`,
{ [DCODE_BASE_IMAGE_ENV]: AMD64_REFERENCE },
),
).toBeUndefined();
});
it("requires publication evidence for the GitHub Actions target", () => {
expect(() =>
loadDcodeBaseImagePublicationEvidence(
DCODE_BASE_IMAGE_TARGET_ID,
`/missing-dcode-base-evidence-${process.pid}.json`,
{
GITHUB_ACTIONS: "true",
[DCODE_BASE_IMAGE_ENV]: AMD64_REFERENCE,
},
),
).toThrow(/GitHub Actions run is missing published base evidence/);
});
it.each([
["missing metadata", null, /missing base resolution metadata/],
[
"the publication index instead of the selected platform",
resolutionMetadata({ digest: INDEX_DIGEST, ref: INDEX_REFERENCE }),
/did not use the published linux\/amd64 base digest/,
],
[
"the opposite platform digest for amd64",
resolutionMetadata({ digest: ARM64_DIGEST, ref: ARM64_REFERENCE }),
/did not use the published linux\/amd64 base digest/,
],
[
"self-consistent opposite-platform metadata",
resolutionMetadata({
architecture: "arm64",
digest: ARM64_DIGEST,
ref: ARM64_REFERENCE,
}),
/did not use the published linux\/amd64 base digest/,
],
[
"a different image repository",
resolutionMetadata({ imageName: "ghcr.io/example/base" }),
/did not use the published linux\/amd64 base digest/,
],
[
"a fallback resolution source",
resolutionMetadata({ source: "latest" }),
/did not use the published linux\/amd64 base digest/,
],
[
"a pinned fallback reference",
resolutionMetadata({ pinnedRemoteRef: AMD64_REFERENCE }),
/did not use the published linux\/amd64 base digest/,
],
[
"an unsupported platform",
resolutionMetadata({ architecture: "ppc64le" }),
/did not use the published linux\/amd64 base digest/,
],
])("rejects %s", (_label, metadata, expectedError) => {
const contract = parseDcodeBaseImagePublicationEvidence(
publicationEvidence(),
publicationEnvironment(),
);
expect(() =>
verifyDcodeBaseImageRuntimeEvidence(
contract,
"nemoclaw-langchain-deepagents-code:e2e",
metadata,
),
).toThrow(expectedError);
});
});