Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/flows/controller-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ a failed retry keeps the active runtime) or whose predecessor stop yielded
require PostgreSQL; none proves model execution.
- [OCC API](../../tests/integration/occ-api.test.mjs) checks deploy audit attribution
and append-failure rollback after an IAM Driver change.
- [Sandbox startup](../../tests/integration/sandbox-driver-startup.test.mjs),
- [Sandbox startup](../../tests/integration/sandbox-driver-startup.test.ts),
[Installation configuration](../../tests/integration/sandbox-driver-installation-configuration.test.ts)
and [IPv6 endpoints](../../tests/integration/sandbox-driver-ipv6-endpoints.test.ts)
check startup. [k3d tests](../../tests/helpers/openshell-sandbox-workflows.mjs)
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/container-release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const runtimeImageSmokeTests = Object.freeze([
"tests/integration/runtime-image-node-state-permissions.test.ts",
"tests/integration/runtime-image-node-state-lock.test.ts",
"tests/integration/runtime-image-codex-local-plugins.test.ts",
"tests/integration/sandbox-driver-startup.test.mjs",
"tests/integration/sandbox-driver-startup.test.ts",
"tests/integration/sandbox-driver-workspace-admission.test.ts",
"tests/integration/sandbox-driver-startup-validation.test.ts",
"tests/integration/sandbox-driver-installation-configuration.test.ts",
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/test-suites/images-runtime-startup-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"tests/integration/runtime-image-model-probe-outcomes.test.ts",
"tests/integration/runtime-image-startup-probe.test.mjs",
"tests/integration/runtime-image-startup-termination.test.ts",
"tests/integration/sandbox-driver-startup.test.mjs",
"tests/integration/sandbox-driver-startup.test.ts",
"tests/integration/sandbox-driver-workspace-admission.test.ts",
"tests/integration/sandbox-driver-startup-validation.test.ts",
"tests/integration/sandbox-driver-installation-configuration.test.ts",
Expand Down Expand Up @@ -63,7 +63,7 @@
]
},
{
"path": "tests/integration/sandbox-driver-startup.test.mjs",
"path": "tests/integration/sandbox-driver-startup.test.ts",
"expectedTests": [
"OpenShell reconciles renewed codex workspace-node setup into its revision provider",
"OpenShell reconciles renewed openclaw workspace-node setup into its revision provider",
Expand Down
71 changes: 44 additions & 27 deletions tests/conformance/selected-openshell-git-runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ test("old attached v5 provider cleanup preserves unrelated resources", async (t)

// Collection is separate from deleting the captured provider attachments above.
const closed = structuredClone(store.rows.get(revision.id));
assert.ok(closed);
assert.equal(closed.blocked, "withdrawn");
const storeCalls = { ...store.calls };
await reconcile();
Expand Down Expand Up @@ -669,9 +670,9 @@ test("fresh repository Git v5 holds and releases one verified launch", async (t)
const route = args[2];
assert.ok(route);
selects.push(structuredClone(route));
return route.fence === store.rows.get(revision.id).fence
? read(...args)
: { absent: "unprepared" };
const row = store.rows.get(revision.id);
assert.ok(row);
return route.fence === row.fence ? read(...args) : { absent: "unprepared" };
};
const update = client.updateProviderCredentialsConditionally?.bind(client);
assert.ok(update);
Expand Down Expand Up @@ -1434,8 +1435,10 @@ test("selected released v5 periodic read crosses admission expiry without grant
const admitted = structuredClone(revision.repositoryCredentials!);
assert.equal(admitted.standingApprovalId, undefined);
assert.ok(admitted.deadlineWallMs > Date.now());
const generation = structuredClone(store.rows.get(revision.id).generation);
const material = structuredClone(store.rows.get(revision.id).material);
const before = store.rows.get(revision.id);
assert.ok(before);
const generation = structuredClone(before.generation);
const material = structuredClone(before.material);
const writes = { updates: activity.updates, rotate: f.calls.rotate };
const read = f.owner.readOpenShellMaterial.bind(f.owner);
let reads = 0;
Expand All @@ -1455,11 +1458,13 @@ test("selected released v5 periodic read crosses admission expiry without grant
reason: "material_unavailable",
});
assert.equal(entry.blocked, undefined);
assert.equal(store.rows.get(revision.id).blocked, undefined);
const after = store.rows.get(revision.id);
assert.ok(after);
assert.equal(after.blocked, undefined);
assert.equal(await lookup(), undefined);
assert.deepEqual(revision.repositoryCredentials, admitted);
assert.deepEqual(store.rows.get(revision.id).generation, generation);
assert.deepEqual(store.rows.get(revision.id).material, material);
assert.deepEqual(after.generation, generation);
assert.deepEqual(after.material, material);
assert.deepEqual({ updates: activity.updates, rotate: f.calls.rotate }, writes);
assert.deepEqual(f.errors(), []);
});
Expand Down Expand Up @@ -2108,6 +2113,7 @@ for (const reason of ["withdrawn", "repository_expired", "worker_replaced"] as c
assert.equal(await lookup(), undefined);
assert.equal(f.denials().at(-1)?.reason, "route_blocked");
if (reason === "worker_replaced") {
assert.ok(moved);
assert.equal(moved.workerInstance, "worker-two");
assert.ok(moved.fence > before.fence);
assert.equal(moved.blocked, "worker_replaced");
Expand Down Expand Up @@ -2175,11 +2181,12 @@ for (const outcome of [
receiptReads,
} = await heldReleased(t);
const before = structuredClone(store.rows.get(revision.id));
assert.ok(before?.generation);
assert.ok(before?.generation && before.material);
assert.equal(before.writePending, undefined);
assert.equal(before.material.materialVersion, f.owner.material.materialVersion);
assert.equal(activity.updates, 1);
assert.ok(await lookup(), "original selected route works before rotation");
const { generation: beforeGeneration, material: beforeMaterial } = before;
const recipient = preview.recipient;
const authorization = structuredClone(entry.authorization);
const launchHash = entry.retainedLaunchHash;
Expand All @@ -2203,6 +2210,7 @@ for (const outcome of [
assert.equal(args[1], originalVersion);
assert.deepEqual(Object.values(args[0].credentials), [nextMaterial.value]);
const pending = structuredClone(store.rows.get(revision.id));
assert.ok(pending?.targetMaterial);
assert.equal(pending.writePending, "rotate");
assert.equal(pending.fence, before.fence + 1);
assert.equal(pending.operationFence, pending.fence);
Expand All @@ -2211,13 +2219,13 @@ for (const outcome of [
assert.equal(pending.targetMaterial.preparationAttemptId, nextMaterial.preparationAttemptId);
assert.notEqual(
pending.targetMaterial.preparationAttemptId,
before.material.preparationAttemptId,
beforeMaterial.preparationAttemptId,
);
assert.notEqual(pending.targetMaterial.materialVersion, before.material.materialVersion);
assert.deepEqual(pending.generation, before.generation);
assert.deepEqual(pending.material, before.material);
assert.notEqual(pending.targetMaterial.materialVersion, beforeMaterial.materialVersion);
assert.deepEqual(pending.generation, beforeGeneration);
assert.deepEqual(pending.material, beforeMaterial);
const result = await update(...args);
assert.equal(result.id, before.generation.providerId);
assert.equal(result.id, beforeGeneration.providerId);
assert.notEqual(result.resourceVersion, originalVersion);
assert.ok(result.resourceVersion);
assert.equal(result.targetReceipts?.length, 1);
Expand All @@ -2226,7 +2234,7 @@ for (const outcome of [
assert.equal(target.kind, "PROVIDER_MUTATION_KIND_UPDATE");
assert.deepEqual(target.desired, {
sandbox: f.sandbox.name,
provider_id: before.generation.providerId,
provider_id: beforeGeneration.providerId,
provider_resource_version: result.resourceVersion,
});
assert.equal(target.receipt_id, updateReceipt(result.resourceVersion));
Expand Down Expand Up @@ -2257,7 +2265,7 @@ for (const outcome of [
await f.runtime["entries"].get(revision.id);
assert.equal(entry.blocked, "withdrawn");
assert.equal(entry.installed, undefined);
assert.equal(store.rows.get(revision.id).blocked, "withdrawn");
assert.equal(store.rows.get(revision.id)?.blocked, "withdrawn");
assert.equal(await lookup(), undefined);
assert.equal(f.denials().at(-1)?.reasonCode, "access_withdrawn");
} else if (outcome === "durable withdrawal") {
Expand All @@ -2268,14 +2276,15 @@ for (const outcome of [
);
await store.withdraw({ revisionId: revision.id });
assert.equal(entry.blocked, undefined, "the withheld reply has not discovered withdrawal");
assert.equal(store.rows.get(revision.id).blocked, "withdrawn");
assert.equal(store.rows.get(revision.id)?.blocked, "withdrawn");
} else if (outcome === "replacement holder") {
await assert.rejects(
prepare(replacement()),
(e: unknown) =>
e instanceof OpenShellGitRouteBlockedError && e.reason === "worker_replaced",
);
const row = store.rows.get(revision.id);
assert.ok(row);
assert.equal(row.fence, before.fence + 2);
assert.notEqual(row.workerInstance, before.workerInstance);
assert.equal(row.blocked, "worker_replaced");
Expand All @@ -2292,6 +2301,7 @@ for (const outcome of [
await premature.catch(() => {});
}
const after = structuredClone(store.rows.get(revision.id));
assert.ok(after);
assert.equal(after.fence, before.fence + (moved ? 2 : 1));
assert.equal(after.operationFence, before.fence + 1);
assert.equal(preview.recipient, recipient);
Expand All @@ -2310,7 +2320,7 @@ for (const outcome of [
assert.equal(f.denials().at(-1)?.reason, "route_blocked");
} else if (outcome !== "accepted") {
assert.equal(after.writePending, "rotate", "accepted but unowned outcome stays pending");
assert.equal(after.targetMaterial.materialVersion, nextMaterial.materialVersion);
assert.equal(after.targetMaterial?.materialVersion, nextMaterial.materialVersion);
assert.deepEqual(after.generation, before.generation);
assert.deepEqual(after.material, before.material);
assert.deepEqual(after.observed, before.observed);
Expand All @@ -2331,10 +2341,10 @@ for (const outcome of [
assert.equal(after.blocked, undefined);
assert.equal(after.writePending, undefined);
assert.equal(after.targetMaterial, undefined);
assert.equal(after.generation.resourceVersion, acceptedVersion);
assert.equal(after.material.materialVersion, nextMaterial.materialVersion);
assert.equal(after.observed.providerResourceVersion, acceptedVersion);
assert.ok(acceptedVersion);
assert.equal(after.generation?.resourceVersion, acceptedVersion);
assert.equal(after.material?.materialVersion, nextMaterial.materialVersion);
assert.equal(after.observed?.providerResourceVersion, acceptedVersion);
const expectedReceipt = updateReceipt(acceptedVersion);
assert.ok(
receiptReads.some(
Expand Down Expand Up @@ -2529,11 +2539,12 @@ for (const phase of ["before first send", "before send", "after acceptance"] as
}
assert.equal((await lookup()) !== undefined, !first);
const row = store.rows.get(revision.id);
assert.ok(row);
assert.ok(row?.generation);
assert.equal(row.material !== undefined, !first);
assert.equal(row.generation.credentialState, first ? "bootstrap" : "active");
const updatesBefore = activity.updates;
const before = structuredClone(row);
assert.ok(before.generation);
const expected = first
? f.owner.material
: { ...f.owner.material, preparationAttemptId: randomUUID(), materialVersion: randomUUID() };
Expand Down Expand Up @@ -2576,7 +2587,7 @@ for (const phase of ["before first send", "before send", "after acceptance"] as
assert.ok(passBudget);
assert.notEqual(args[2], passBudget);
assert.equal(row.writePending, "rotate");
assert.equal(row.generation.resourceVersion, before.generation.resourceVersion);
assert.equal(row.generation?.resourceVersion, before.generation?.resourceVersion);
await waitForExpiry(passBudget);
assert.equal(args[2].aborted, false, "an accepted update has its own write budget");
}
Expand Down Expand Up @@ -2673,7 +2684,7 @@ for (const { first, outcome } of [true, false].flatMap((first) =>
const initialRelease = preview.release;
const originalMaterial = f.owner.material;
if (!first) {
assert.equal(before.material.materialVersion, originalMaterial.materialVersion);
assert.equal(before.material?.materialVersion, originalMaterial.materialVersion);
assert.equal(initialRelease, "acknowledged");
}
const originalVersion = entry.binding.resourceVersion;
Expand Down Expand Up @@ -2732,6 +2743,7 @@ for (const { first, outcome } of [true, false].flatMap((first) =>
try {
await Promise.race([reached.promise, premature]);
const pending = store.rows.get(revision.id);
assert.ok(pending?.targetMaterial && pending.generation && pending.observed);
assert.equal(reads.length, 2);
assert.equal(reads[0]?.[2]?.fence, before.fence);
assert.equal(reads[1]?.[2]?.fence, before.fence + 1);
Expand Down Expand Up @@ -2767,6 +2779,7 @@ for (const { first, outcome } of [true, false].flatMap((first) =>
assert.equal(store.calls.cancelWriting, cancellations);
}
const uncertain = structuredClone(store.rows.get(revision.id));
assert.ok(uncertain);
assert.equal(uncertain.fence, before.fence + 1);
assert.equal(uncertain.operationFence, before.fence + 1);
assert.equal(uncertain.blocked, undefined);
Expand Down Expand Up @@ -2826,6 +2839,7 @@ for (const { first, outcome } of [true, false].flatMap((first) =>
error instanceof OpenShellGitRouteBlockedError && error.reason === "worker_replaced",
);
const moved = structuredClone(store.rows.get(revision.id));
assert.ok(moved);
assert.equal(moved.fence, before.fence + 2);
assert.notEqual(moved.workerInstance, before.workerInstance);
assert.equal(moved.blocked, "worker_replaced");
Expand All @@ -2835,11 +2849,12 @@ for (const { first, outcome } of [true, false].flatMap((first) =>
assert.equal(retries.length, 0);
assert.equal(order.length, 0);
const after = store.rows.get(revision.id);
assert.ok(after);
assert.equal(after.fence, moved.fence);
assert.equal(after.workerInstance, moved.workerInstance);
assert.equal(after.operationFence, before.fence + 1);
assert.equal(after.writePending, "rotate");
assert.equal(after.targetMaterial.materialVersion, nextMaterial.materialVersion);
assert.equal(after.targetMaterial?.materialVersion, nextMaterial.materialVersion);
assert.equal(after.blocked, "worker_replaced");
assert.deepEqual(f.runtime.route(revision.id), { state: "none" });
assert.equal(f.runtime.previewReleased(revision.id), false);
Expand All @@ -2857,6 +2872,7 @@ for (const { first, outcome } of [true, false].flatMap((first) =>
assert.equal(retryResults[0], outcome === "not committed");
assert.equal(entry.unsentWrite, undefined);
const after = store.rows.get(revision.id);
assert.ok(after);
assert.equal(after.fence, before.fence + (first ? 2 : 1));
assert.equal(after.workerInstance, before.workerInstance);
assert.equal(after.operationFence, before.fence + (first ? 2 : 1));
Expand Down Expand Up @@ -2889,15 +2905,16 @@ for (const { first, outcome } of [true, false].flatMap((first) =>
assert.equal(warnings().length, 1);
}
const after = store.rows.get(revision.id);
assert.ok(after?.generation);
const firstSent = first && outcome !== "replacement holder";
const finalVersion = firstSent ? entry.binding.resourceVersion : originalVersion;
assert.equal(after.generation.resourceVersion, finalVersion);
if (firstSent) {
assert.equal(after.material.materialVersion, originalMaterial.materialVersion);
assert.equal(after.material?.materialVersion, originalMaterial.materialVersion);
} else {
assert.deepEqual(after.material, before.material);
}
assert.equal(after.observed.providerResourceVersion, finalVersion);
assert.equal(after.observed?.providerResourceVersion, finalVersion);
assert.equal(entry.binding.resourceVersion, finalVersion);
assert.equal(preview.release, firstSent ? "acknowledged" : initialRelease);
assert.equal(preview.recipient, recipient);
Expand Down
17 changes: 17 additions & 0 deletions tests/fixtures/kubernetes-provider-endpoint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,28 @@ export function tlsPinnedWorkspaceSetupCode(url, expiresAtMs) {

// In-memory Kubernetes transport plus Sandbox/lifecycle responses. No cluster I/O.
// Tests own readiness transitions and assertions; prepare/activate remain real Driver calls.
/**
* @param {{
* credentialGatewayDriver?: import("../../packages/contracts/src/index.ts").CredentialGatewayDriver,
* harnessEndpoint?: (context: import("../../packages/contracts/src/index.ts").SandboxHarnessContext) => Promise<import("../../packages/contracts/src/index.ts").SandboxHarnessEndpoint | undefined>,
* providerNetwork?: import("../../apps/controller/src/drivers/compute/kubernetes/index.ts").KubernetesComputeDriverOptions["network"]["providerHarness"],
* revisionOverrides?: Partial<import("../../packages/contracts/src/index.ts").AgentRevision>,
* servicePrincipalCredentials?: import("../../apps/controller/src/drivers/compute/kubernetes/index.ts").KubernetesComputeDriverOptions["servicePrincipalCredentials"],
* gatewayRouting?: import("../../apps/controller/src/drivers/compute/kubernetes/index.ts").KubernetesGatewayRoutingOptions,
* sandboxDriver?: import("../../packages/contracts/src/index.ts").SandboxDriver,
* }} [options]
*/
export function providerEndpointFixture({
credentialGatewayDriver,
harnessEndpoint = async () => ({
url: "ws://tenant--sandbox.openshell.localhost:8080/",
workspaceRoot: "/sandbox/enterprise",
}),
providerNetwork,
revisionOverrides,
servicePrincipalCredentials,
gatewayRouting,
sandboxDriver,
} = {}) {
const hooks = [];
const provisions = [];
Expand All @@ -105,9 +119,12 @@ export function providerEndpointFixture({
const peerLookups = [];
const provisioningPolicies = [];
const fixture = providerReadinessFixture({
credentialGatewayDriver,
providerNetwork,
revisionOverrides,
servicePrincipalCredentials,
gatewayRouting,
sandboxDriver,
// The Sandbox, and so its relay Pod's labels, exists only once provisioned.
async workspaceNodePeerLabels({ revision: target }) {
peerLookups.push(target.id);
Expand Down
9 changes: 7 additions & 2 deletions tests/fixtures/kubernetes-provider-readiness.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function supervisorPeerLabels(revisionId) {
}

export function providerReadinessFixture({
credentialGatewayDriver,
provisionHarness,
harnessEndpoint,
providerNetwork = {
Expand All @@ -38,6 +39,8 @@ export function providerReadinessFixture({
audience: "openclaw-controller",
expirationSeconds: 900,
},
gatewayRouting,
sandboxDriver,
workspaceNodePeerLabels = async ({ revision }) => supervisorPeerLabels(revision.id),
} = {}) {
const driver = new KubernetesComputeDriver(
Expand All @@ -47,6 +50,7 @@ export function providerReadinessFixture({
gatewayStorageClassName: "local-path",
},
servicePrincipalCredentials,
...(gatewayRouting === undefined ? {} : { gatewayRouting }),
...(harnessEndpoint === undefined
? {}
: {
Expand All @@ -57,12 +61,13 @@ export function providerReadinessFixture({
}),
{
lifecycleDrivers,
credentialGatewayDriver,
nodeEnrollment: nodeEnrollment ?? {
async isConnected() {
return true;
},
},
sandboxDriver: {
sandboxDriver: sandboxDriver ?? {
id: "sandbox-provider",
implementation: "openshell",
async provisionHarness(context) {
Expand All @@ -77,7 +82,7 @@ export function providerReadinessFixture({
},
);
const revision = routedRevision(driver, {
sandboxDriverId: "sandbox-provider",
sandboxDriverId: sandboxDriver?.id ?? "sandbox-provider",
configuration: admitLoggingConfiguration(
{
agents: { defaults: { model: "codex/gpt-5" } },
Expand Down
Loading
Loading