Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Refuse in-memory stores, locks and leases in production instead of falling back silently (#2453)

Regan Bellec50f3edb7ab
diff --git a/deploy/helm/README.md b/deploy/helm/README.md
index d698e78a6..157639d80 100644
--- a/deploy/helm/README.md
+++ b/deploy/helm/README.md
@@ -120,9 +120,8 @@ and `S3_REGION` (optionally `S3_PREFIX`) on core, use a remote `SANDBOX_BACKEND`
and leave `services.core.persistence` disabled. Sessions and runs then live in
Postgres, and uploaded artifacts, session shares, published-app source archives and
sandbox file transfers go to the bucket, so replicas share that state and pods can
-be replaced with rolling updates. Without `SESSION_STORE=postgres`, sessions and
-runs stay in process memory even when `DATABASE_URL` is set; an explicit
-`RUN_STORE=memory` also keeps runs there. S3
+be replaced with rolling updates. Production core refuses to start without
+`DATABASE_URL` and `SESSION_STORE=postgres`, or with `RUN_STORE=memory`. S3
credentials come from the standard AWS chain, such as a pod IAM role bound through
`serviceAccount.create=true` with `serviceAccount.annotations`, or
`AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY` in the runtime Secret. Any S3-compatible
diff --git a/docs/porter.md b/docs/porter.md
index 9b7360471..505a9ab0b 100644
--- a/docs/porter.md
+++ b/docs/porter.md
@@ -128,7 +128,7 @@ Nothing generates the inter-service wiring for you — `cli/src/services.ts` has
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| all | `CORE_ORG_ID`/`ORG_ID`, `CORE_SIGNING_SECRET`, `PORTAL_IDENTITY_SECRET` |
| all but core | `CORE_API_URL=http://qm-core-core.<namespace>.svc.cluster.local:8080` |
-| core | `MODEL_PROVIDER`, `HARNESS`, `SANDBOX_BACKEND`, `PUBLIC_WEB_URL`/`WEB_UI_PUBLIC_URL` (the portal's hostname), `CAPABILITY_SECRET`, `CONNECTOR_SECRET_KEY`, `SKILL_SIGNING_SECRET`, and `DATABASE_URL` when `SESSION_STORE`/`RUN_STORE` are `postgres` |
+| core | `MODEL_PROVIDER`, `HARNESS`, `SANDBOX_BACKEND`, `PUBLIC_WEB_URL`/`WEB_UI_PUBLIC_URL` (the portal's hostname), `CAPABILITY_SECRET`, `CONNECTOR_SECRET_KEY`, `SKILL_SIGNING_SECRET`, `DATABASE_URL` and `SESSION_STORE=postgres` — production refuses to boot without them |
| portal | `PORTAL_PUBLIC_URL`, `PORTAL_SESSION_SECRET`, `WEB_UI_UPSTREAM`, `ADMIN_UPSTREAM`, `AUTH_BROKER_UPSTREAM`, `AUTH_BROKER_PREFIX=/idp`, the `OIDC_*` set from `brokerWiring` in `cli/src/services.ts` (including `OIDC_CLIENT_SECRET`), and `OIDC_ALLOWED_EMAILS` or `OIDC_ALLOWED_EMAIL_DOMAIN` — production refuses to boot without an allow-list |
| admin | `ADMIN_BASE_PATH=/admin` |
| auth | `AUTH_ISSUER=<portal>/idp`, `AUTH_CLIENT_ID`, `AUTH_CLIENT_SECRET`, `AUTH_REDIRECT_URI=<portal>/auth/callback`, `AUTH_TOKEN_SECRET`, `AUTH_SIGNING_JWK` (a P-256 private JWK), `AUTH_EMAIL_FROM`, and `AUTH_EMAIL_TRANSPORT` with a `RESEND_API_KEY` or SMTP credentials — without a mail transport nobody can sign in |
diff --git a/scripts/aws-deploy-smoke.ts b/scripts/aws-deploy-smoke.ts
index 720b1512a..7450a7b52 100644
--- a/scripts/aws-deploy-smoke.ts
+++ b/scripts/aws-deploy-smoke.ts
@@ -9,6 +9,7 @@ import type { Deployment, DeploymentVersion } from "../src/deploy/deploy-store.t
import { swallow } from "../src/util/errors.ts";
import { scopeId } from "../src/types.ts";
import { loadConfig } from "../src/config.ts";
+import { createNoopAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const { awsDeploy } = loadConfig();
const region = awsDeploy.region;
@@ -17,7 +18,7 @@ const appPort = awsDeploy.appPort ?? 8081;
const api = createMicrovmApi({ region, ...(awsDeploy.profile ? { profile: awsDeploy.profile } : {}) });
const store = createMemoryMap<StoredDeployBody>();
-const provider = createAwsDeployProvider({ ...awsDeploy, store });
+const provider = createAwsDeployProvider({ advisoryLock: createNoopAdvisoryLock(), ...awsDeploy, store });
function makeVersion(v: number): DeploymentVersion {
const snapshotDir = mkdtempSync(join(tmpdir(), `aws-deploy-app-v${v}-`));
diff --git a/scripts/aws-litestream-smoke.ts b/scripts/aws-litestream-smoke.ts
index ca9abdd82..b8f21ed90 100644
--- a/scripts/aws-litestream-smoke.ts
+++ b/scripts/aws-litestream-smoke.ts
@@ -12,6 +12,7 @@ import type { Deployment, DeploymentVersion } from "../src/deploy/deploy-store.t
import { loadConfig } from "../src/config.ts";
import { sleep } from "../src/util/async.ts";
import { scopeId } from "../src/types.ts";
+import { createNoopAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const { awsDeploy } = loadConfig();
if (!awsDeploy.dataBucket || !awsDeploy.dataRoleArn)
@@ -24,7 +25,7 @@ const api = createMicrovmApi({
});
const client = createMicrovmClient(api, { agentPort: awsDeploy.agentPort ?? 8080, tokenTtlMinutes: 30 });
const store = createMemoryMap<StoredDeployBody>();
-const provider = createAwsDeployProvider({ ...awsDeploy, store, api });
+const provider = createAwsDeployProvider({ advisoryLock: createNoopAdvisoryLock(), ...awsDeploy, store, api });
const s3 = new S3Client({ region: awsDeploy.region, ...(awsDeploy.profile ? { profile: awsDeploy.profile } : {}) });
const APP = `
diff --git a/scripts/aws-sandbox-smoke.ts b/scripts/aws-sandbox-smoke.ts
index c1d07b447..b3f856153 100644
--- a/scripts/aws-sandbox-smoke.ts
+++ b/scripts/aws-sandbox-smoke.ts
@@ -8,6 +8,8 @@ import { createMicrovmApi } from "../src/sandbox/aws-microvm-api.ts";
import { createLocalWorkspaceStore } from "../src/workspace/workspace-store.ts";
import { scopeId } from "../src/types.ts";
import { scopeStorageKey } from "../cli/src/scope-storage-key.ts";
+import { createNoopAdvisoryLock } from "../src/persistence/advisory-lock.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
const region = process.env.AWS_SANDBOX_REGION ?? "us-west-2";
const profile = process.env.AWS_SANDBOX_PROFILE ?? "dev";
@@ -21,6 +23,8 @@ async function main(): Promise<void> {
if (!s3Bucket) throw new Error("AWS_SANDBOX_S3_BUCKET is required");
const ws = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "aws-smoke-ws-")));
const sandbox = createAwsSandbox(ws, {
+ store: createMemoryMap(),
+ advisoryLock: createNoopAdvisoryLock(),
region,
profile,
imageIdentifier,
diff --git a/scripts/managed-agents-sandbox-smoke.ts b/scripts/managed-agents-sandbox-smoke.ts
index 96ba31e6f..834fcbced 100644
--- a/scripts/managed-agents-sandbox-smoke.ts
+++ b/scripts/managed-agents-sandbox-smoke.ts
@@ -8,6 +8,8 @@ import { createManagedAgentsSandbox } from "../src/sandbox/managed-agents-sandbo
import { createSdkManagedAgentsClient } from "../src/sandbox/managed-agents-client.ts";
import { createLocalWorkspaceStore } from "../src/workspace/workspace-store.ts";
import { scopeId } from "../src/types.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
+import { createMemorySnapshotStore } from "../src/sandbox/home-snapshot.ts";
const apiToken = process.env.DO_AGENTS_API_TOKEN;
const apiBaseUrl = process.env.DO_AGENTS_API_BASE_URL;
@@ -33,6 +35,8 @@ async function main(): Promise<void> {
{
client,
namePrefix: prefix,
+ store: createMemoryMap(),
+ snapshots: createMemorySnapshotStore(),
},
);
const scope = scopeId("personal", "smoke");
diff --git a/scripts/monitor-smoke.ts b/scripts/monitor-smoke.ts
index d2833e91a..0cd3e210c 100644
--- a/scripts/monitor-smoke.ts
+++ b/scripts/monitor-smoke.ts
@@ -14,6 +14,9 @@ import { createDeliveryStore } from "../src/delivery/delivery-store.ts";
import { createIdempotencyStore } from "../src/idempotency/idempotency-store.ts";
import { createIdentityService } from "../src/identity/identity-service.ts";
import { loadConfig } from "../src/config.ts";
+import { createNoopLeaderLease } from "../src/persistence/leader-lease.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
if (!process.env.SPRITES_TOKEN) {
console.error("set SPRITES_TOKEN (mint one with `sprite login`)");
@@ -52,7 +55,11 @@ print("PHASE: image saved diffusion-out.png", flush=True)
`;
const ws = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "monitor-smoke-")));
-const sb = createSpritesSandbox(ws, loadConfig().spritesSandbox);
+const sb = createSpritesSandbox(ws, {
+ ...loadConfig().spritesSandbox,
+ initializationStore: createMemoryMap(),
+ advisoryLock: createMemoryAdvisoryLock(),
+});
if (!supportsProcessSessions(sb)) throw new Error("Sprites sandbox does not advertise process sessions");
const scope = scopeId("personal", "qm-monitor-smoke");
@@ -89,6 +96,7 @@ const monitorBroker = createMonitorBroker({
const wakes: TurnRequest[] = [];
const poller = createMonitorPoller({
+ leaderLease: createNoopLeaderLease(),
monitors,
processes: registry,
sandbox: sb,
diff --git a/scripts/skills-materialize-smoke.ts b/scripts/skills-materialize-smoke.ts
index e714d04d8..f51f6cca6 100644
--- a/scripts/skills-materialize-smoke.ts
+++ b/scripts/skills-materialize-smoke.ts
@@ -8,6 +8,8 @@ import { loadConfig } from "../src/config.ts";
import { materializeSkillTree } from "../src/skills/materialize.ts";
import { computeBundleHash, type SkillBundle } from "../src/skills/skill-bundle-store.ts";
import type { SkillFile, SkillResolution } from "../src/skills/skill-store.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
if (!process.env.SPRITES_TOKEN) {
console.error("set SPRITES_TOKEN (mint one with `sprite login`)");
@@ -26,7 +28,11 @@ function assert(cond: unknown, msg: string): void {
const scope = scopeId("personal", "qm-skills-smoke");
const ws = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "skills-smoke-")));
-const sb = createSpritesSandbox(ws, loadConfig().spritesSandbox);
+const sb = createSpritesSandbox(ws, {
+ ...loadConfig().spritesSandbox,
+ initializationStore: createMemoryMap(),
+ advisoryLock: createMemoryAdvisoryLock(),
+});
let h: Awaited<ReturnType<typeof sb.provision>> | undefined;
try {
diff --git a/src/api/slack-core-client.ts b/src/api/slack-core-client.ts
index 69fe9a099..ef39a81c8 100644
--- a/src/api/slack-core-client.ts
+++ b/src/api/slack-core-client.ts
@@ -20,7 +20,7 @@ import { Readable } from "node:stream";
import { buffer } from "node:stream/consumers";
import type { App } from "./app.ts";
import type { ErrorLog } from "../admin/error-log.ts";
-import { createNoopLeaderLease, type LeaderLease } from "../persistence/leader-lease.ts";
+import type { LeaderLease } from "../persistence/leader-lease.ts";
import type {
Delivery,
PendingApproval,
@@ -165,7 +165,7 @@ export interface SlackCoreClientDeps {
ackPicks?: AckEmojiPickStore;
ackModelId?: () => string | undefined;
brandingDefault?: OrgBranding;
- leaderLease?: LeaderLease;
+ leaderLease: LeaderLease;
stagedEnvelopes?: DurableMap<StagedEnvelope>;
surfaceCache?: SurfaceCache;
memory?: MemoryService;
@@ -176,7 +176,7 @@ const RUN_FALLBACK_POLL_MS = 1_000;
const RUN_STALL_BUDGET_MS = 300_000;
export function createSlackCoreClient(deps: SlackCoreClientDeps): SlackCoreClient {
- const lease = deps.leaderLease ?? createNoopLeaderLease();
+ const lease = deps.leaderLease;
const orgScope: ScopeId = scopeId("org", configOrgId());
const terminalWaiters = new Map<string, Set<() => void>>();
deps.runs.onTerminal((run) => {
diff --git a/src/config.ts b/src/config.ts
index 0b97d112c..8e4f3d729 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -28,7 +28,7 @@ import { parseMemoryStrategyKind, type MemoryStrategyKind } from "./memory/strat
import { parseMemoryProviderConfig, type MemoryProviderConfig } from "./memory/provider-config.ts";
import { sanitizeBranding } from "./resolution/branding.ts";
import type { OrgBranding } from "./resolution/config-store.ts";
-import { validateCoreSecretEnv } from "./deployment/secret-schema.ts";
+import { CORE_SECRET_SPECS, validateCoreSecretEnv } from "./deployment/secret-schema.ts";
import { DEFAULT_CAPTURE_QUIET_MS } from "./memory/strategies/per-turn.ts";
import {
parseSecurityPosture,
@@ -1179,6 +1179,25 @@ function modelProviderEnvStrict(env: NodeJS.ProcessEnv): ModelProvider | undefin
return declared;
}
+function resolveStoreKinds(env: NodeJS.ProcessEnv): Pick<Config, "sessionStore" | "runStore"> {
+ for (const key of ["SESSION_STORE", "RUN_STORE", "ARTIFACT_STORE"] as const) {
+ if (env[key] === "sqlite") {
+ throw new Error(
+ `${key}=sqlite is no longer supported — SQLite was removed. ` +
+ `Set ${key === "ARTIFACT_STORE" ? "DATABASE_URL (Postgres)" : `${key}=postgres (with DATABASE_URL)`}.`,
+ );
+ }
+ }
+ const sessionStore = env.SESSION_STORE === "postgres" ? "postgres" : "memory";
+ const runStore = env.RUN_STORE === "memory" || env.RUN_STORE === "postgres" ? env.RUN_STORE : sessionStore;
+ if (env.NODE_ENV === "production" && (sessionStore === "memory" || runStore === "memory")) {
+ throw new Error(
+ `production requires SESSION_STORE=postgres and a Postgres run store (got SESSION_STORE=${env.SESSION_STORE ?? "unset"}, RUN_STORE=${env.RUN_STORE ?? "unset"}): in-memory sessions and runs are lost on restart and invisible to other instances.`,
+ );
+ }
+ return { sessionStore, runStore };
+}
+
export function loadConfig(env: NodeJS.ProcessEnv = process.env): Config {
const token = env.SPEND_EXPORT_TOKEN;
if (token) {
@@ -1223,26 +1242,22 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): Config {
const deployAppsDomain = deployAppsDomainEnv(env, env.DEPLOY_PROVIDER ?? "docker");
const missingSecrets = validateCoreSecretEnv(env);
if (missingSecrets.length) {
- throw new Error(`missing or insecure required core secrets: ${missingSecrets.join(", ")}`);
+ const described = missingSecrets.map((name) => {
+ const reason = CORE_SECRET_SPECS.find((spec) => spec.name === name)?.reason;
+ return reason ? `${name} (${reason})` : name;
+ });
+ throw new Error(`missing or insecure required core secrets: ${described.join(", ")}`);
}
const modelProvider = modelProviderEnvStrict(env);
- for (const key of ["SESSION_STORE", "RUN_STORE", "ARTIFACT_STORE"] as const) {
- if (env[key] === "sqlite") {
- throw new Error(
- `${key}=sqlite is no longer supported — SQLite was removed. ` +
- `Set ${key === "ARTIFACT_STORE" ? "DATABASE_URL (Postgres)" : `${key}=postgres (with DATABASE_URL)`} for durability, ` +
- `or use the in-memory default (${key === "ARTIFACT_STORE" ? "unset ARTIFACT_STORE" : `${key}=memory`}) for an ephemeral store.`,
- );
- }
- }
+ const { sessionStore, runStore } = resolveStoreKinds(env);
if (env.E2B_API_KEY && !env.E2B_SNAPSHOT_S3_BUCKET) {
console.warn(
- "[config] e2b sandbox backend enabled without E2B_SNAPSHOT_S3_BUCKET — provider pause preserves the machine, but portable recovery snapshots are memory-only; set E2B_SNAPSHOT_S3_BUCKET for durable portable recovery.",
+ "[config] e2b sandbox backend enabled without E2B_SNAPSHOT_S3_BUCKET — provider pause preserves the machine, but there are no home snapshots, so a sandbox the provider loses comes back with an empty home; set E2B_SNAPSHOT_S3_BUCKET for durable portable recovery.",
);
}
if (env.MODAL_TOKEN_ID && env.MODAL_TOKEN_SECRET && !env.MODAL_SNAPSHOT_S3_BUCKET) {
console.warn(
- "[config] modal sandbox backend enabled without MODAL_SNAPSHOT_S3_BUCKET — native home checkpoints have limited retention; portable recovery snapshots are memory-only. Set MODAL_SNAPSHOT_S3_BUCKET for durable portable recovery and configure DATABASE_URL for durable checkpoint references.",
+ "[config] modal sandbox backend enabled without MODAL_SNAPSHOT_S3_BUCKET — there are no home snapshots, so unless native home checkpoints are enabled (limited retention) the home is lost at Modal's 24h sandbox lifetime. Set MODAL_SNAPSHOT_S3_BUCKET for durable portable recovery and configure DATABASE_URL for durable checkpoint references.",
);
}
if (env.SMOLMACHINES_TOKEN && !env.SMOLMACHINES_SNAPSHOT_S3_BUCKET) {
@@ -1336,13 +1351,6 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): Config {
"SANDBOX_BACKEND=superserve requires SUPERSERVE_TEMPLATE, the ready qm-agent-<release> template that carries the agent toolchain.",
);
}
- const superserveEnabled =
- superserveSelected || Boolean(env.SUPERSERVE_API_KEY?.trim() && env.SUPERSERVE_TEMPLATE?.trim());
- if (superserveEnabled && env.NODE_ENV === "production" && !env.DATABASE_URL?.trim()) {
- throw new Error(
- "the superserve sandbox backend requires DATABASE_URL in production: the config generation and the provisioning lock have to be durable across instances, or a blue-green rollout can destroy a scope's resident disk.",
- );
- }
if (env.SANDBOX_SECONDARY_BACKEND?.trim()) {
console.warn(
@@ -1427,8 +1435,6 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): Config {
`DEPLOY_PROVIDER=${JSON.stringify(deployProvider)} is not recognized (expected aws, docker, fly, porter, or e2b)`,
);
}
- let runStore: "memory" | "postgres" = env.SESSION_STORE === "postgres" ? "postgres" : "memory";
- if (env.RUN_STORE === "memory" || env.RUN_STORE === "postgres") runStore = env.RUN_STORE;
const providerBaseUrls = providerBaseUrlsFromEnv(env);
const modelGateway = modelGatewayFromEnv(env);
const brokerCredentials = deploymentBrokerCredentialsFromEnv(env);
@@ -1484,7 +1490,7 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): Config {
...(env.POSTHOG_API_KEY?.trim()
? { productAnalytics: { apiKey: env.POSTHOG_API_KEY.trim(), host: env.POSTHOG_HOST?.trim() } }
: {}),
- sessionStore: env.SESSION_STORE === "postgres" ? "postgres" : "memory",
+ sessionStore,
...(env.DATABASE_URL ? { databaseUrl: env.DATABASE_URL } : {}),
...(env.DATABASE_POOL_URL ? { databasePoolUrl: env.DATABASE_POOL_URL } : {}),
...(env.DATABASE_POOL_CA_CERT ? { databasePoolCaCert: env.DATABASE_POOL_CA_CERT } : {}),
diff --git a/src/core/orchestrator.ts b/src/core/orchestrator.ts
index 11e2b31e7..e9d4db3e2 100644
--- a/src/core/orchestrator.ts
+++ b/src/core/orchestrator.ts
@@ -114,8 +114,7 @@ import {
import { commandApprovalId, inputApprovalId } from "./approval-id.ts";
import { createPerTurnStrategy } from "../memory/strategies/per-turn.ts";
import { DEFAULT_MEMORY_POLICY } from "../memory/policy.ts";
-import { createMemoryMap } from "../persistence/durable-map.ts";
-import { collectBlob, createMemoryBlobTransferStore } from "../persistence/blob-transfer.ts";
+import { collectBlob } from "../persistence/blob-transfer.ts";
import { skillsIndex } from "../skills/materialize.ts";
import { isIdeasConversation, PROACTIVE_OPENER_PROMPT } from "../onboarding/onboarding.ts";
import { createToolContext, NeedsApproval, CommandDenied, type CommandCredential } from "../tools/primitives.ts";
@@ -255,13 +254,13 @@ export function createOrchestrator(deps: OrchestratorDeps): Orchestrator {
);
}
const leaseKeepaliveMs = Math.floor(deps.sessions.leaseTtlMs / 3);
- const pending = deps.approvals ?? createMemoryMap<PendingApprovalRecord>();
+ const pending = deps.approvals;
const transcripts = createTranscriptSource(deps.sessions);
- const approvalGrants = deps.approvalGrants ?? createMemoryMap<CommandApprovalGrant>();
+ const approvalGrants = deps.approvalGrants;
const memoryPolicy = deps.memoryPolicy ?? DEFAULT_MEMORY_POLICY;
const memoryStrategy =
deps.memoryStrategy ?? createPerTurnStrategy({ harness: deps.harness.models, memory: deps.memory });
- const blobTransfer = deps.blobTransfer ?? createMemoryBlobTransferStore();
+ const blobTransfer = deps.blobTransfer;
const pendingCaptures = new Map<ScopeId, Promise<void>>();
diff --git a/src/core/orchestrator/types.ts b/src/core/orchestrator/types.ts
index 4de9beb2c..0ea3c7496 100644
--- a/src/core/orchestrator/types.ts
+++ b/src/core/orchestrator/types.ts
@@ -169,15 +169,15 @@ export interface OrchestratorDeps {
skillBundles?: SkillBundleStore;
skillsReady?: Promise<void>;
advisoryLock?: AdvisoryLock;
- approvals?: DurableMap<PendingApprovalRecord>;
- approvalGrants?: DurableMap<CommandApprovalGrant>;
+ approvals: DurableMap<PendingApprovalRecord>;
+ approvalGrants: DurableMap<CommandApprovalGrant>;
errors?: ErrorLog;
ledger?: ToolLedger;
signals?: RunSignalStore;
turnStream?: TurnStream;
runActivity?: RunActivityStore;
runs?: RunStore;
- blobTransfer?: BlobTransferStore;
+ blobTransfer: BlobTransferStore;
processes?: ProcessRegistry;
monitors?: MonitorStore;
crons?: CronStore;
diff --git a/src/credentials/keychain.ts b/src/credentials/keychain.ts
index 740685cec..884dc2bc3 100644
--- a/src/credentials/keychain.ts
+++ b/src/credentials/keychain.ts
@@ -1,4 +1,4 @@
-import { createMemoryAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import { orgId as configOrgId } from "../config.ts";
import { randomBytes } from "node:crypto";
import { validateHeaderName, validateHeaderValue } from "node:http";
@@ -608,14 +608,14 @@ export function createKeychain(deps: {
grants: DurableMap<KeychainGrant>;
asks: DurableMap<KeychainAsk>;
key: SecretKey;
- lock?: AdvisoryLock;
+ lock: AdvisoryLock;
refreshConnector?: OAuthRefresh;
oauthSkewMs?: number;
oauthRefreshMarginMs?: number;
now?: () => number;
}): Keychain {
const now = deps.now ?? Date.now;
- const lock = deps.lock ?? createMemoryAdvisoryLock();
+ const lock = deps.lock;
const oauthSkew = deps.oauthSkewMs ?? 60_000;
const oauthRefreshMargin = Math.max(deps.oauthRefreshMarginMs ?? 10 * 60_000, oauthSkew);
diff --git a/src/cron/scheduler.ts b/src/cron/scheduler.ts
index 5b08369e6..dc924a674 100644
--- a/src/cron/scheduler.ts
+++ b/src/cron/scheduler.ts
@@ -10,7 +10,7 @@ import { runTrigger, type TriggerDeps } from "../triggers/run-trigger.ts";
import type { CurrentScopeMembers } from "../resolution/scope-membership.ts";
import type { VisibilityDirectory } from "../directory/visibility.ts";
import type { DirectoryMember } from "../directory/directory-store.ts";
-import { createNoopLeaderLease, type LeaderLease } from "../persistence/leader-lease.ts";
+import type { LeaderLease } from "../persistence/leader-lease.ts";
import { createSweeper } from "../util/sweeper.ts";
import { recoverNextFireAt } from "./schedule.ts";
import type { CronFireJob, CronJobQueue } from "./job-queue.ts";
@@ -64,7 +64,7 @@ export interface Scheduler {
export interface SchedulerDeps {
admittedWork?: AdmittedWork;
- lock?: import("../persistence/advisory-lock.ts").AdvisoryLock;
+ advisoryLock: import("../persistence/advisory-lock.ts").AdvisoryLock;
crons: CronStore;
deliveries: DeliveryStore;
idempotency: IdempotencyStore;
@@ -73,7 +73,7 @@ export interface SchedulerDeps {
currentScopeMembers?: CurrentScopeMembers;
now?: () => number;
maxFiresPerTick?: number;
- leaderLease?: LeaderLease;
+ leaderLease: LeaderLease;
directory?: VisibilityDirectory & {
get(principalId: string): Promise<{ displayName: string } | null>;
list(): Promise<DirectoryMember[]>;
@@ -188,15 +188,15 @@ export function createScheduler(deps: SchedulerDeps): Scheduler {
const now = deps.now ?? (() => Date.now());
const withWork = <T>(work: () => Promise<T>): Promise<T> => deps.admittedWork?.run(work) ?? work();
const maxFiresPerTick = deps.maxFiresPerTick ?? 100;
- const leaderLease = deps.leaderLease ?? createNoopLeaderLease();
+ const leaderLease = deps.leaderLease;
async function withCronLifecycle<T>(cronId: string, scheduled: boolean, run: () => Promise<T>): Promise<T | null> {
- if (scheduled && deps.lock?.tryWithLock) {
- const result = await deps.lock.tryWithLock(`cron-lifecycle:${cronId}`, run);
+ if (scheduled && deps.advisoryLock.tryWithLock) {
+ const result = await deps.advisoryLock.tryWithLock(`cron-lifecycle:${cronId}`, run);
if (result === null) await deps.crons.defer(cronId, now() + BUSY_DEFER_MS);
return result;
}
- return deps.lock ? deps.lock.withLock(`cron-lifecycle:${cronId}`, run) : run();
+ return deps.advisoryLock.withLock(`cron-lifecycle:${cronId}`, run);
}
async function fire(cron: Cron, t: number, fireKey: string, scheduledAt?: number): Promise<FireResult> {
diff --git a/src/deploy/aws-deploy-provider.ts b/src/deploy/aws-deploy-provider.ts
index 604edfb9a..25f464cf0 100644
--- a/src/deploy/aws-deploy-provider.ts
+++ b/src/deploy/aws-deploy-provider.ts
@@ -6,7 +6,7 @@ import type { DeployEndpoint, DeployProvider, DeployReconcileInput } from "./dep
import { bytes, normalizeRelPath, posixJoin, readTree } from "./deploy-fs.ts";
import { AwsApiError, createMicrovmApi, createMicrovmClient, type AwsMicrovmApi } from "../sandbox/aws-microvm-api.ts";
import { createMemoryMap, type DurableMap } from "../persistence/durable-map.ts";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import { createKeyedQueue, sleep } from "../util/async.ts";
import { shq } from "../util/shell.ts";
import { execFailure, swallow, swallowAs } from "../util/errors.ts";
@@ -89,7 +89,7 @@ export interface AwsDeployProviderOptions {
snapshotIntervalMs?: number;
dataRoleArn?: string;
store?: DurableMap<StoredDeployBody>;
- advisoryLock?: AdvisoryLock;
+ advisoryLock: AdvisoryLock;
api?: AwsMicrovmApi;
fetchImpl?: typeof fetch;
s3?: Pick<S3Client, "send">;
@@ -108,7 +108,7 @@ export function createAwsDeployProvider(opts: AwsDeployProviderOptions): DeployP
});
const store = opts.store ?? createMemoryMap<StoredDeployBody>();
const launchQueue = createKeyedQueue<string>();
- const advisoryLock = opts.advisoryLock ?? createNoopAdvisoryLock();
+ const advisoryLock = opts.advisoryLock;
const resolveCache = new Map<string, { endpoint: DeployEndpoint; checkedMs: number; usedMs: number }>();
const inflightResolves = new Map<string, Promise<DeployEndpoint | null>>();
const resolveGens = new Map<string, number>();
diff --git a/src/deploy/deploy-service.ts b/src/deploy/deploy-service.ts
index 774f8ed69..38db0c442 100644
--- a/src/deploy/deploy-service.ts
+++ b/src/deploy/deploy-service.ts
@@ -22,8 +22,8 @@ import {
type DeploymentVersion,
} from "./deploy-store.ts";
import type { DeployProfile, DeployProvider } from "./deploy-provider.ts";
-import { createNoopLeaderLease, type LeaderLease } from "../persistence/leader-lease.ts";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { LeaderLease } from "../persistence/leader-lease.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import { createKeyedQueue } from "../util/async.ts";
import { errMessage, reportFailure, swallow, swallowAs } from "../util/errors.ts";
@@ -141,8 +141,8 @@ export interface DeployServiceDeps {
auditLog: AuditLog;
appPublished?: (principal: string, deploymentId: string, version: number) => Promise<void>;
acl: AclStore;
- leaderLease?: LeaderLease;
- advisoryLock?: AdvisoryLock;
+ leaderLease: LeaderLease;
+ advisoryLock: AdvisoryLock;
canReadScope?: (principalId: string, scopeId: ScopeId) => Promise<boolean>;
canWriteScope?: (principalId: string, scopeId: ScopeId) => Promise<boolean>;
canManageEmail?: (email: string) => Promise<boolean>;
@@ -193,8 +193,8 @@ function requiredEntrypoint(input: string | undefined, d: Deployment | null): st
}
export function createDeployService(deps: DeployServiceDeps): DeployService {
- const leaderLease = deps.leaderLease ?? createNoopLeaderLease();
- const advisoryLock = deps.advisoryLock ?? createNoopAdvisoryLock();
+ const leaderLease = deps.leaderLease;
+ const advisoryLock = deps.advisoryLock;
const deployQueue = createKeyedQueue();
const externalSharingAllowed = (ownerScopeId: ScopeId): Promise<boolean> =>
deps.externalSharingAllowed?.(ownerScopeId) ?? Promise.resolve(false);
diff --git a/src/deploy/e2b-deploy-provider.ts b/src/deploy/e2b-deploy-provider.ts
index 046a2e3ab..f45fa36e6 100644
--- a/src/deploy/e2b-deploy-provider.ts
+++ b/src/deploy/e2b-deploy-provider.ts
@@ -17,7 +17,7 @@ import {
import { makeTar } from "../sandbox/tar.ts";
import { E2bSandboxGoneError, runE2bScript, type E2bClient, type E2bSession } from "../sandbox/e2b-client.ts";
import { createMemoryMap, type DurableMap } from "../persistence/durable-map.ts";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import { createKeyedQueue } from "../util/async.ts";
import { shq } from "../util/shell.ts";
import { execFailure, swallow } from "../util/errors.ts";
@@ -51,7 +51,7 @@ export interface E2bDeployProviderOptions {
idleTimeoutSec?: number;
resolveCacheMs?: number;
store?: DurableMap<StoredE2bDeployBody>;
- advisoryLock?: AdvisoryLock;
+ advisoryLock: AdvisoryLock;
onError?: AppErrorSink;
}
@@ -63,7 +63,7 @@ export function createE2bDeployProvider(opts: E2bDeployProviderOptions): DeployP
const idleTimeoutMs = (opts.idleTimeoutSec ?? E2B_DEPLOY_IDLE_TIMEOUT_SEC) * 1000;
const resolveCacheMs = opts.resolveCacheMs ?? RESOLVE_CACHE_MS_DEFAULT;
const store = opts.store ?? createMemoryMap<StoredE2bDeployBody>();
- const advisoryLock = opts.advisoryLock ?? createNoopAdvisoryLock();
+ const advisoryLock = opts.advisoryLock;
const queue = createKeyedQueue<string>();
const resolveCache = new LRUCache<string, DeployEndpoint>({
max: RESOLVE_CACHE_MAX,
diff --git a/src/deploy/porter-deploy-provider.ts b/src/deploy/porter-deploy-provider.ts
index d5a0752f3..fae23265b 100644
--- a/src/deploy/porter-deploy-provider.ts
+++ b/src/deploy/porter-deploy-provider.ts
@@ -29,7 +29,7 @@ import {
type PorterSandboxLike,
} from "../sandbox/porter-client.ts";
import { createMemoryMap, type DurableMap } from "../persistence/durable-map.ts";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import { createKeyedQueue } from "../util/async.ts";
import { shq } from "../util/shell.ts";
import { execFailure, swallow, swallowAs } from "../util/errors.ts";
@@ -72,7 +72,7 @@ export interface PorterDeployProviderOptions {
resolveCacheMs?: number;
client?: PorterClientLike;
store?: DurableMap<StoredPorterDeployBody>;
- advisoryLock?: AdvisoryLock;
+ advisoryLock: AdvisoryLock;
onError?: AppErrorSink;
}
@@ -85,7 +85,7 @@ export function createPorterDeployProvider(opts: PorterDeployProviderOptions): D
const readyWindowSec = opts.readyWindowSec ?? APP_READY_WINDOW_SEC_DEFAULT;
const resolveCacheMs = opts.resolveCacheMs ?? RESOLVE_CACHE_MS_DEFAULT;
const store = opts.store ?? createMemoryMap<StoredPorterDeployBody>();
- const advisoryLock = opts.advisoryLock ?? createNoopAdvisoryLock();
+ const advisoryLock = opts.advisoryLock;
const queue = createKeyedQueue<string>();
const client: PorterClientLike =
opts.client ??
diff --git a/src/deployment/deployment-layer-store.ts b/src/deployment/deployment-layer-store.ts
index 1310346be..574976cea 100644
--- a/src/deployment/deployment-layer-store.ts
+++ b/src/deployment/deployment-layer-store.ts
@@ -1,5 +1,5 @@
import { createHash } from "node:crypto";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import type { DurableMap } from "../persistence/durable-map.ts";
import type { ScopeId } from "../types.ts";
import {
@@ -271,7 +271,7 @@ export function createDeploymentLayerStore(opts: {
durable?: boolean;
now?: () => number;
retryDelaysMs?: readonly number[];
- advisoryLock?: AdvisoryLock;
+ advisoryLock: AdvisoryLock;
auditPersisted?: (record: StoredDeploymentLayer) => Promise<void>;
}): DeploymentLayerStore {
const now = opts.now ?? Date.now;
@@ -280,7 +280,7 @@ export function createDeploymentLayerStore(opts: {
let failedHash: string | null = null;
let seeded = false;
const queue = createKeyedQueue<string>();
- const advisoryLock = opts.advisoryLock ?? createNoopAdvisoryLock();
+ const advisoryLock = opts.advisoryLock;
const withFleetLock = <T>(fn: () => Promise<T>): Promise<T> => advisoryLock.withLock(SKILL_MATERIALIZATION_LOCK, fn);
const retrying = async <T>(fn: () => Promise<T>): Promise<T> => {
diff --git a/src/deployment/secret-schema.ts b/src/deployment/secret-schema.ts
index fa80a495a..9855bdd01 100644
--- a/src/deployment/secret-schema.ts
+++ b/src/deployment/secret-schema.ts
@@ -28,6 +28,7 @@ type SecretGate =
export interface RuntimeSecretSpec {
name: string;
requiredWhen: SecretGate | readonly SecretGate[];
+ reason?: string;
}
export const CORE_SECRET_SPECS: readonly RuntimeSecretSpec[] = [
@@ -41,7 +42,12 @@ export const CORE_SECRET_SPECS: readonly RuntimeSecretSpec[] = [
{ name: "OPENAI_API_KEY", requiredWhen: ["model-openai"] },
{ name: "ANTHROPIC_API_KEY", requiredWhen: "model-anthropic" },
{ name: "OPENROUTER_API_KEY", requiredWhen: "model-openrouter" },
- { name: "DATABASE_URL", requiredWhen: "postgres" },
+ {
+ name: "DATABASE_URL",
+ requiredWhen: ["production", "postgres"],
+ reason:
+ "sessions, runs, approvals, audit, locks and leases must survive restarts and be shared across instances, or a blue-green rollout can destroy a scope's resident disk",
+ },
{ name: "SPRITES_TOKEN", requiredWhen: "sprites" },
{ name: "SMOLMACHINES_TOKEN", requiredWhen: "smolmachines" },
{ name: "AGENT37_API_KEY", requiredWhen: "agent37" },
diff --git a/src/monitors/monitor-poller.ts b/src/monitors/monitor-poller.ts
index 28149639f..2dcce02c2 100644
--- a/src/monitors/monitor-poller.ts
+++ b/src/monitors/monitor-poller.ts
@@ -8,7 +8,7 @@ import type { IdentityService } from "../identity/identity-service.ts";
import { supportsProcessSessions, type ProcessSandbox, type Sandbox, type SandboxHandle } from "../sandbox/sandbox.ts";
import { ProcessSessionGoneError } from "../sandbox/exec-process-session.ts";
import { runTrigger, type TriggerDeps, type TriggerOutcome } from "../triggers/run-trigger.ts";
-import { createNoopLeaderLease, type LeaderLease } from "../persistence/leader-lease.ts";
+import type { LeaderLease } from "../persistence/leader-lease.ts";
import { createSweeper } from "../util/sweeper.ts";
import { errMessage, reportFailureAs } from "../util/errors.ts";
import type { CurrentScopeMembers } from "../resolution/scope-membership.ts";
@@ -43,7 +43,7 @@ export interface MonitorPollerDeps {
resolveRecipient?: TriggerDeps["resolveRecipient"];
now?: () => number;
maxFiresPerTick?: number;
- leaderLease?: LeaderLease;
+ leaderLease: LeaderLease;
onProcessExit?: (handle: SandboxHandle, processId: string) => Promise<void>;
heartbeatMs?: number;
minFireIntervalMs?: number;
@@ -131,7 +131,7 @@ export function createMonitorPoller(deps: MonitorPollerDeps): MonitorPoller {
const maxFiresPerTick = deps.maxFiresPerTick ?? 20;
const heartbeatMs = deps.heartbeatMs ?? DEFAULT_HEARTBEAT_MS;
const minFireIntervalMs = deps.minFireIntervalMs ?? DEFAULT_MIN_FIRE_INTERVAL_MS;
- const leaderLease = deps.leaderLease ?? createNoopLeaderLease();
+ const leaderLease = deps.leaderLease;
const triggerDeps: TriggerDeps = {
deliveries: deps.deliveries,
diff --git a/src/processes/process-reaper.ts b/src/processes/process-reaper.ts
index 3c90af5f6..e8af96dd8 100644
--- a/src/processes/process-reaper.ts
+++ b/src/processes/process-reaper.ts
@@ -1,6 +1,6 @@
import type { ProcessRecord, ProcessRegistry } from "./process-registry.ts";
import { createSweeper } from "../util/sweeper.ts";
-import { createNoopLeaderLease, type LeaderLease } from "../persistence/leader-lease.ts";
+import type { LeaderLease } from "../persistence/leader-lease.ts";
import { awaitProcessExit } from "../sandbox/await-process-exit.ts";
import { ProcessSessionGoneError } from "../sandbox/exec-process-session.ts";
import type { ProcessSandbox, SandboxHandle } from "../sandbox/sandbox.ts";
@@ -62,11 +62,11 @@ export interface ProcessReaperOptions {
intervalMs: number;
kill?: (rec: ProcessRecord) => Promise<void>;
onReaped?: (rec: ProcessRecord) => Promise<void>;
- leaderLease?: LeaderLease;
+ leaderLease: LeaderLease;
}
export function createProcessReaper(registry: ProcessRegistry, opts: ProcessReaperOptions): ProcessReaper {
- const leaderLease = opts.leaderLease ?? createNoopLeaderLease();
+ const leaderLease = opts.leaderLease;
async function sweep(): Promise<{ reaped: number }> {
const expired = await registry.listExpired();
let reaped = 0;
diff --git a/src/projects/project-store.ts b/src/projects/project-store.ts
index 3f39aa892..0d9659780 100644
--- a/src/projects/project-store.ts
+++ b/src/projects/project-store.ts
@@ -1,7 +1,7 @@
import { randomUUID } from "node:crypto";
import { orgId as configOrgId } from "../config.ts";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
-import { createMemoryMap, type DurableMap } from "../persistence/durable-map.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { DurableMap } from "../persistence/durable-map.ts";
import { scopeId, type ScopeId } from "../types.ts";
import { samePerson } from "../directory/person.ts";
import { createKeyedQueue } from "../util/async.ts";
@@ -95,18 +95,18 @@ function visible(project: Project): Project {
}
export function createProjectStore(
- backing: DurableMap<Project> = createMemoryMap<Project>(),
+ backing: DurableMap<Project>,
opts: {
now?: () => number;
id?: () => string;
isActiveMember?: (principalId: string) => boolean;
- advisoryLock?: AdvisoryLock;
- } = {},
+ advisoryLock: AdvisoryLock;
+ },
): ProjectStore {
const now = opts.now ?? Date.now;
const nextId = opts.id ?? randomUUID;
const isActiveMember = opts.isActiveMember ?? (() => true);
- const advisoryLock = opts.advisoryLock ?? createNoopAdvisoryLock();
+ const advisoryLock = opts.advisoryLock;
const queue = createKeyedQueue<string>();
const withLock = <T>(id: string, fn: () => Promise<T>): Promise<T> =>
queue(id, () => advisoryLock.withLock(`project:${id}`, fn));
diff --git a/src/runs/reaper.ts b/src/runs/reaper.ts
index 363f4bf7d..c772ff7d3 100644
--- a/src/runs/reaper.ts
+++ b/src/runs/reaper.ts
@@ -3,7 +3,7 @@ import type { SessionStore } from "../sessions/session-store.ts";
import type { ErrorLog } from "../admin/error-log.ts";
import type { ScopeId } from "../types.ts";
import { createSweeper } from "../util/sweeper.ts";
-import { createNoopLeaderLease, type LeaderLease } from "../persistence/leader-lease.ts";
+import type { LeaderLease } from "../persistence/leader-lease.ts";
export const REAPER_LEASE_KEY = "runs:reaper";
@@ -32,13 +32,13 @@ async function releaseStrandedSessionLeases(sessions: SessionStore, sessionIds:
export interface ReaperOptions {
intervalMs: number;
- leaderLease?: LeaderLease;
+ leaderLease: LeaderLease;
maxAgeMs?: number;
errors?: ErrorLog;
}
export function createReaper(runs: RunStore, sessions: SessionStore, opts: ReaperOptions): Reaper {
- const leaderLease = opts.leaderLease ?? createNoopLeaderLease();
+ const leaderLease = opts.leaderLease;
const { errors } = opts;
const reap = (): Promise<{ requeued: number; parked: number }> =>
runs.reapExpired((retiredSessionIds) => releaseStrandedSessionLeases(sessions, retiredSessionIds), {
diff --git a/src/sandbox/agent37-sandbox.ts b/src/sandbox/agent37-sandbox.ts
index 587489113..6078a4d6b 100644
--- a/src/sandbox/agent37-sandbox.ts
+++ b/src/sandbox/agent37-sandbox.ts
@@ -17,7 +17,7 @@ import {
} from "../credentials/resident-paths.ts";
import { DROPPED_PROXY_ENV, forceThroughProxyEnv } from "./sandbox-env.ts";
import type { BlobTransferStore } from "../persistence/blob-transfer.ts";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import { killableScript, killScript } from "./exec-kill.ts";
import { visibleNotInstalled, visibleTools } from "./sandbox.ts";
import { sandboxScopeName } from "./exec-sandbox-base.ts";
@@ -119,11 +119,11 @@ export interface Agent37SandboxOptions {
extraTools?: string[];
credentialPaths?: CredentialPathSpec[];
fetchImpl?: typeof fetch;
- advisoryLock?: AdvisoryLock;
+ advisoryLock: AdvisoryLock;
onError?: (e: { category: string; code: string; message: string; scopeLabel?: string }) => void;
}
-export function createAgent37Sandbox(workspace: WorkspaceStore, opts: Agent37SandboxOptions = {}): Sandbox {
+export function createAgent37Sandbox(workspace: WorkspaceStore, opts: Agent37SandboxOptions): Sandbox {
if (!opts.apiKey && !opts.fetchImpl) throw new Error("SANDBOX_BACKEND=agent37 requires AGENT37_API_KEY");
const fetchImpl = opts.fetchImpl ?? fetch;
const baseUrl = (opts.baseUrl ?? DEFAULT_AGENT37_BASE_URL).replace(/\/+$/, "");
@@ -135,7 +135,7 @@ export function createAgent37Sandbox(workspace: WorkspaceStore, opts: Agent37San
disk: opts.diskGb ?? DEFAULT_DISK_GB,
};
const defaultTimeoutSec = opts.defaultTimeoutSec ?? 600;
- const advisoryLock = opts.advisoryLock ?? createNoopAdvisoryLock();
+ const advisoryLock = opts.advisoryLock;
const workspaceDir = `${HOME_DIR}/${WORKSPACE_BASENAME}`;
const provisionQueue = createKeyedQueue<string>();
diff --git a/src/sandbox/aws-sandbox.ts b/src/sandbox/aws-sandbox.ts
index 4c5866e19..9bf1419a0 100644
--- a/src/sandbox/aws-sandbox.ts
+++ b/src/sandbox/aws-sandbox.ts
@@ -3,8 +3,8 @@ import { DeleteObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { orgId as configOrgId } from "../config.ts";
import type { WorkspaceLayer } from "../types.ts";
import type { WorkspaceStore } from "../workspace/workspace-store.ts";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
-import { createMemoryMap, type DurableMap } from "../persistence/durable-map.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { DurableMap } from "../persistence/durable-map.ts";
import { createKeyedQueue } from "../util/async.ts";
import { scopeStorageKey } from "../../cli/src/scope-storage-key.ts";
import { swallowAs, errMessage } from "../util/errors.ts";
@@ -83,8 +83,8 @@ export interface AwsSandboxOptions extends BlobStagingOptions {
cpus?: number;
memoryMb?: number;
diskGb?: number;
- store?: DurableMap<StoredMicrovm>;
- advisoryLock?: AdvisoryLock;
+ store: DurableMap<StoredMicrovm>;
+ advisoryLock: AdvisoryLock;
extraTools?: string[];
credentialPaths?: CredentialPathSpec[];
onError?: (e: { category: string; code: string; message: string; scopeLabel?: string }) => void;
@@ -109,8 +109,8 @@ export function createAwsSandbox(workspace: WorkspaceStore, opts: AwsSandboxOpti
});
const s3: Pick<S3Client, "send"> =
opts.s3 ?? new S3Client({ region, ...(opts.profile ? { profile: opts.profile } : {}) });
- const store = opts.store ?? createMemoryMap<StoredMicrovm>();
- const advisoryLock = opts.advisoryLock ?? createNoopAdvisoryLock();
+ const store = opts.store;
+ const advisoryLock = opts.advisoryLock;
const provisionQueue = createKeyedQueue<string>();
const withScopeLock = <T>(scope: string, run: () => Promise<T>): Promise<T> =>
provisionQueue(scope, () => advisoryLock.withLock(`aws-provision:${scope}`, run));
diff --git a/src/sandbox/e2b-sandbox.ts b/src/sandbox/e2b-sandbox.ts
index f99c85089..c2a7ab9ff 100644
--- a/src/sandbox/e2b-sandbox.ts
+++ b/src/sandbox/e2b-sandbox.ts
@@ -3,8 +3,7 @@ import { randomUUID } from "node:crypto";
import type { WorkspaceLayer } from "../types.ts";
import type { WorkspaceStore } from "../workspace/workspace-store.ts";
import type { DurableMap } from "../persistence/durable-map.ts";
-import { createMemoryMap } from "../persistence/durable-map.ts";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import { createKeyedQueue } from "../util/async.ts";
import { swallowAs, errMessage } from "../util/errors.ts";
import { shq } from "../util/shell.ts";
@@ -36,13 +35,7 @@ import {
type E2bSession,
runE2bScript,
} from "./e2b-client.ts";
-import {
- createHomeSnapshotOps,
- createMemorySnapshotStore,
- HOME_SNAPSHOT_PRUNE,
- snapshotDue,
- type HomeSnapshotStore,
-} from "./home-snapshot.ts";
+import { createHomeSnapshotOps, HOME_SNAPSHOT_PRUNE, snapshotDue, type HomeSnapshotStore } from "./home-snapshot.ts";
import type {
AgentComputerProfile,
ComputerStatus,
@@ -79,7 +72,7 @@ export interface StoredE2bSandbox {
export const E2B_TEMPLATE_TOOLS = ["wget", "unzip", "gh", "aws", "x-api"];
export interface E2bSandboxOptions extends BlobStagingOptions {
- advisoryLock?: AdvisoryLock;
+ advisoryLock: AdvisoryLock;
client: E2bClient;
namePrefix?: string;
defaultTimeoutSec?: number;
@@ -91,7 +84,7 @@ export interface E2bSandboxOptions extends BlobStagingOptions {
extraTools?: string[];
credentialPaths?: CredentialPathSpec[];
layerToolFiles?: () => readonly LayerInstallFile[];
- store?: DurableMap<StoredE2bSandbox>;
+ store: DurableMap<StoredE2bSandbox>;
snapshots?: HomeSnapshotStore;
onError?: (e: { category: string; code: string; message: string; scopeLabel?: string }) => void;
}
@@ -109,10 +102,9 @@ export function createE2bSandbox(workspace: WorkspaceStore, opts: E2bSandboxOpti
if (info?.memoryMb) observed.memoryMb = info.memoryMb;
};
const workspaceDir = `${HOME_DIR}/${WORKSPACE_BASENAME}`;
- const store = opts.store ?? createMemoryMap<StoredE2bSandbox>();
- const snapshots = opts.snapshots ?? createMemorySnapshotStore();
+ const store = opts.store;
const localQueue = createKeyedQueue<string>();
- const advisoryLock = opts.advisoryLock ?? createNoopAdvisoryLock();
+ const advisoryLock = opts.advisoryLock;
const provisionQueue = <T>(scope: string, action: () => Promise<T>): Promise<T> =>
localQueue(scope, () => advisoryLock.withLock(`e2b-provision:${scope}`, action));
@@ -125,26 +117,32 @@ export function createE2bSandbox(workspace: WorkspaceStore, opts: E2bSandboxOpti
opts.onError?.({ category, code, message, ...(scopeLabel ? { scopeLabel } : {}) });
};
- const homeSnapshots = createHomeSnapshotOps<E2bSession>({
- label: "e2b",
- homeDir: HOME_DIR,
- homeTarPath: HOME_TAR,
- prunePaths: [...SNAPSHOT_PRUNE, ...ephemeralCredLinkPaths(opts.credentialPaths ?? []).map(({ rel }) => `./${rel}`)],
- store: snapshots,
- io: {
- runCommand: (session, script, timeoutMs) => session.runCommand(script, { timeoutMs }),
- readFileBytes: (session, abs) => session.readFileBytes(abs),
- writeFileBytes: (session, abs, data) => session.writeFileBytes(abs, data),
- },
- });
+ const homeSnapshots = opts.snapshots
+ ? createHomeSnapshotOps<E2bSession>({
+ label: "e2b",
+ homeDir: HOME_DIR,
+ homeTarPath: HOME_TAR,
+ prunePaths: [
+ ...SNAPSHOT_PRUNE,
+ ...ephemeralCredLinkPaths(opts.credentialPaths ?? []).map(({ rel }) => `./${rel}`),
+ ],
+ store: opts.snapshots,
+ io: {
+ runCommand: (session, script, timeoutMs) => session.runCommand(script, { timeoutMs }),
+ readFileBytes: (session, abs) => session.readFileBytes(abs),
+ writeFileBytes: (session, abs, data) => session.writeFileBytes(abs, data),
+ },
+ })
+ : undefined;
async function snapshotHome(scope: string, session: E2bSession): Promise<void> {
+ if (!homeSnapshots) return;
await homeSnapshots.snapshotHome(scope, session);
await store.merge(scope, { lastSnapshotMs: Date.now(), homeDirty: false });
}
- const hydrateHome = (scope: string, session: E2bSession): Promise<boolean> =>
- homeSnapshots.hydrateHome(scope, session);
+ const hydrateHome = async (scope: string, session: E2bSession): Promise<boolean> =>
+ homeSnapshots ? homeSnapshots.hydrateHome(scope, session) : false;
async function ensureSession(
scope: string,
@@ -499,12 +497,16 @@ export function createE2bSandbox(workspace: WorkspaceStore, opts: E2bSandboxOpti
exportFiles: execExport.exportFiles,
- async persistHomeSnapshot(scopeId: string): Promise<void> {
- const name = sandboxScopeName(prefix, scopeId);
- scopeByName.set(name, scopeId);
- const { session } = await ensureSession(scopeId, name);
- await snapshotHome(scopeId, session);
- },
+ ...(homeSnapshots
+ ? {
+ async persistHomeSnapshot(scopeId: string): Promise<void> {
+ const name = sandboxScopeName(prefix, scopeId);
+ scopeByName.set(name, scopeId);
+ const { session } = await ensureSession(scopeId, name);
+ await snapshotHome(scopeId, session);
+ },
+ }
+ : {}),
async computerStatus(scopeId: string): Promise<ComputerStatus> {
const name = sandboxScopeName(prefix, scopeId);
diff --git a/src/sandbox/managed-agents-sandbox.ts b/src/sandbox/managed-agents-sandbox.ts
index 8d344dcb4..2c64d0df5 100644
--- a/src/sandbox/managed-agents-sandbox.ts
+++ b/src/sandbox/managed-agents-sandbox.ts
@@ -3,7 +3,6 @@ import { randomUUID } from "node:crypto";
import type { WorkspaceLayer } from "../types.ts";
import type { WorkspaceStore } from "../workspace/workspace-store.ts";
import type { DurableMap } from "../persistence/durable-map.ts";
-import { createMemoryMap } from "../persistence/durable-map.ts";
import { createKeyedQueue } from "../util/async.ts";
import { swallowAs, errMessage } from "../util/errors.ts";
import { shq } from "../util/shell.ts";
@@ -34,13 +33,7 @@ import {
type ManagedAgentsSessionInfo,
type ManagedAgentsSession,
} from "./managed-agents-client.ts";
-import {
- createHomeSnapshotOps,
- createMemorySnapshotStore,
- HOME_SNAPSHOT_PRUNE,
- snapshotDue,
- type HomeSnapshotStore,
-} from "./home-snapshot.ts";
+import { createHomeSnapshotOps, HOME_SNAPSHOT_PRUNE, snapshotDue, type HomeSnapshotStore } from "./home-snapshot.ts";
import type {
AgentComputerProfile,
ComputerStatus,
@@ -93,7 +86,7 @@ export interface ManagedAgentsSandboxOptions extends BlobStagingOptions {
extraTools?: string[];
credentialPaths?: CredentialPathSpec[];
layerToolFiles?: () => readonly LayerInstallFile[];
- store?: DurableMap<StoredManagedAgentsSandbox>;
+ store: DurableMap<StoredManagedAgentsSandbox>;
snapshots?: HomeSnapshotStore;
onError?: (e: { category: string; code: string; message: string; scopeLabel?: string }) => void;
}
@@ -104,8 +97,7 @@ export function createManagedAgentsSandbox(workspace: WorkspaceStore, opts: Mana
const defaultTimeoutSec = opts.defaultTimeoutSec ?? 600;
const snapshotIntervalMs = opts.snapshotIntervalMs ?? DEFAULT_SNAPSHOT_INTERVAL_MS;
const workspaceDir = `${HOME_DIR}/${WORKSPACE_BASENAME}`;
- const store = opts.store ?? createMemoryMap<StoredManagedAgentsSandbox>();
- const snapshots = opts.snapshots ?? createMemorySnapshotStore();
+ const store = opts.store;
const provisionQueue = createKeyedQueue<string>();
const sessionByName = new Map<string, ManagedAgentsSession>();
@@ -117,20 +109,26 @@ export function createManagedAgentsSandbox(workspace: WorkspaceStore, opts: Mana
opts.onError?.({ category, code, message, ...(scopeLabel ? { scopeLabel } : {}) });
};
- const homeSnapshots = createHomeSnapshotOps<ManagedAgentsSession>({
- label: "do-managed-agents",
- homeDir: HOME_DIR,
- homeTarPath: HOME_TAR,
- prunePaths: [...SNAPSHOT_PRUNE, ...ephemeralCredLinkPaths(opts.credentialPaths ?? []).map(({ rel }) => `./${rel}`)],
- store: snapshots,
- io: {
- runCommand: (session, script, timeoutMs) => session.runCommand(script, { timeoutMs }),
- readFileBytes: (session, abs) => session.readFileBytes(abs),
- writeFileBytes: (session, abs, data) => session.writeFileBytes(abs, data),
- },
- });
+ const homeSnapshots = opts.snapshots
+ ? createHomeSnapshotOps<ManagedAgentsSession>({
+ label: "do-managed-agents",
+ homeDir: HOME_DIR,
+ homeTarPath: HOME_TAR,
+ prunePaths: [
+ ...SNAPSHOT_PRUNE,
+ ...ephemeralCredLinkPaths(opts.credentialPaths ?? []).map(({ rel }) => `./${rel}`),
+ ],
+ store: opts.snapshots,
+ io: {
+ runCommand: (session, script, timeoutMs) => session.runCommand(script, { timeoutMs }),
+ readFileBytes: (session, abs) => session.readFileBytes(abs),
+ writeFileBytes: (session, abs, data) => session.writeFileBytes(abs, data),
+ },
+ })
+ : undefined;
async function snapshotHome(scope: string, session: ManagedAgentsSession): Promise<void> {
+ if (!homeSnapshots) return;
await homeSnapshots.snapshotHome(scope, session);
await store.merge(scope, { lastSnapshotMs: Date.now(), homeDirty: false });
}
@@ -174,8 +172,8 @@ export function createManagedAgentsSandbox(workspace: WorkspaceStore, opts: Mana
if (previous && previous !== captured.checkpointId) await forgetCheckpoint(scope, session, previous);
}
- const hydrateHome = (scope: string, session: ManagedAgentsSession): Promise<boolean> =>
- homeSnapshots.hydrateHome(scope, session);
+ const hydrateHome = async (scope: string, session: ManagedAgentsSession): Promise<boolean> =>
+ homeSnapshots ? homeSnapshots.hydrateHome(scope, session) : false;
const recordSession = (scope: string, session: ManagedAgentsSession, createdAtMs: number): Promise<void> =>
store.put(scope, {
@@ -504,12 +502,16 @@ export function createManagedAgentsSandbox(workspace: WorkspaceStore, opts: Mana
exportFiles: execExport.exportFiles,
- async persistHomeSnapshot(scopeId: string): Promise<void> {
- const name = sandboxScopeName(prefix, scopeId);
- scopeByName.set(name, scopeId);
- const { session } = await ensureSession(scopeId, name);
- await snapshotHome(scopeId, session);
- },
+ ...(homeSnapshots
+ ? {
+ async persistHomeSnapshot(scopeId: string): Promise<void> {
+ const name = sandboxScopeName(prefix, scopeId);
+ scopeByName.set(name, scopeId);
+ const { session } = await ensureSession(scopeId, name);
+ await snapshotHome(scopeId, session);
+ },
+ }
+ : {}),
async restartComputer(scopeId: string): Promise<void> {
const name = sandboxScopeName(prefix, scopeId);
diff --git a/src/sandbox/modal-sandbox.ts b/src/sandbox/modal-sandbox.ts
index 406c93c54..5dd4e32c3 100644
--- a/src/sandbox/modal-sandbox.ts
+++ b/src/sandbox/modal-sandbox.ts
@@ -2,9 +2,8 @@ import { cleanupFailedProvision } from "./sandbox.ts";
import { randomUUID } from "node:crypto";
import type { WorkspaceLayer } from "../types.ts";
import type { WorkspaceStore } from "../workspace/workspace-store.ts";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import type { DurableMap } from "../persistence/durable-map.ts";
-import { createMemoryMap } from "../persistence/durable-map.ts";
import { orgId as configOrgId } from "../config.ts";
import { createKeyedQueue } from "../util/async.ts";
import { swallowAs, errMessage } from "../util/errors.ts";
@@ -31,13 +30,7 @@ import { killableScript, killScript } from "./exec-kill.ts";
import { visibleNotInstalled, visibleTools } from "./sandbox.ts";
import { sandboxScopeName } from "./exec-sandbox-base.ts";
import { ModalNameConflictError, ModalSandboxGoneError, type ModalClient, type ModalSession } from "./modal-client.ts";
-import {
- createHomeSnapshotOps,
- createMemorySnapshotStore,
- HOME_SNAPSHOT_PRUNE,
- snapshotDue,
- type HomeSnapshotStore,
-} from "./home-snapshot.ts";
+import { createHomeSnapshotOps, HOME_SNAPSHOT_PRUNE, snapshotDue, type HomeSnapshotStore } from "./home-snapshot.ts";
import type {
AgentComputerProfile,
ComputerStatus,
@@ -79,7 +72,7 @@ export interface StoredModalSandbox {
export interface ModalSandboxOptions extends BlobStagingOptions {
client: ModalClient;
- advisoryLock?: AdvisoryLock;
+ advisoryLock: AdvisoryLock;
namePrefix?: string;
defaultTimeoutSec?: number;
snapshotIntervalMs?: number;
@@ -97,7 +90,7 @@ export interface ModalSandboxOptions extends BlobStagingOptions {
lifetimeMarginMs?: number;
checkpointRenewMarginMs?: number;
orphanGraceMs?: number;
- store?: DurableMap<StoredModalSandbox>;
+ store: DurableMap<StoredModalSandbox>;
snapshots?: HomeSnapshotStore;
onError?: (e: { category: string; code: string; message: string; scopeLabel?: string }) => void;
}
@@ -127,10 +120,9 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
"qm-kind": kind,
});
const workspaceDir = `${HOME_DIR}/${WORKSPACE_BASENAME}`;
- const store = opts.store ?? createMemoryMap<StoredModalSandbox>();
- const snapshots = opts.snapshots ?? createMemorySnapshotStore();
+ const store = opts.store;
const localQueue = createKeyedQueue<string>();
- const advisoryLock = opts.advisoryLock ?? createNoopAdvisoryLock();
+ const advisoryLock = opts.advisoryLock;
const provisionQueue = <T>(scope: string, action: () => Promise<T>): Promise<T> =>
localQueue(scope, () => advisoryLock.withLock(`modal-provision:${scope}`, action));
@@ -143,19 +135,24 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
opts.onError?.({ category, code, message, ...(scopeLabel ? { scopeLabel } : {}) });
};
- const homeSnapshots = createHomeSnapshotOps<ModalSession>({
- label: "modal",
- homeDir: HOME_DIR,
- homeTarPath: HOME_TAR,
- prunePaths: [...SNAPSHOT_PRUNE, ...ephemeralCredLinkPaths(opts.credentialPaths ?? []).map(({ rel }) => `./${rel}`)],
- store: snapshots,
- io: {
- runCommand: (session, script, timeoutMs) => session.runCommand(script, { timeoutMs }),
- readFileBytes: (session, abs) => session.readFileBytes(abs),
- writeFileBytes: (session, abs, data) => session.writeFileBytes(abs, data),
- },
- partBytes: fileChunkBytes,
- });
+ const homeSnapshots = opts.snapshots
+ ? createHomeSnapshotOps<ModalSession>({
+ label: "modal",
+ homeDir: HOME_DIR,
+ homeTarPath: HOME_TAR,
+ prunePaths: [
+ ...SNAPSHOT_PRUNE,
+ ...ephemeralCredLinkPaths(opts.credentialPaths ?? []).map(({ rel }) => `./${rel}`),
+ ],
+ store: opts.snapshots,
+ io: {
+ runCommand: (session, script, timeoutMs) => session.runCommand(script, { timeoutMs }),
+ readFileBytes: (session, abs) => session.readFileBytes(abs),
+ writeFileBytes: (session, abs, data) => session.writeFileBytes(abs, data),
+ },
+ partBytes: fileChunkBytes,
+ })
+ : undefined;
async function assertHydrated(session: ModalSession): Promise<void> {
const marked = await session.runCommand(`test -f ${shq(HYDRATED_MARKER)}`, { timeoutMs: 30_000 });
@@ -205,7 +202,7 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
);
throw error;
}
- } else {
+ } else if (homeSnapshots) {
await homeSnapshots.snapshotHome(scope, session);
await store.merge(scope, { lastSnapshotMs: Date.now(), homeDirty: false });
}
@@ -263,7 +260,7 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
await session.restoreHome(previous.nativeSnapshotId);
hydrated = true;
} else {
- hydrated = await homeSnapshots.hydrateHome(scope, session);
+ hydrated = homeSnapshots ? await homeSnapshots.hydrateHome(scope, session) : false;
}
} catch (e) {
await store.merge(scope, { recoveryError: errMessage(e) });
@@ -308,6 +305,7 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
const stale =
allowRotation &&
!!stored &&
+ (!!homeSnapshots || usesNativeSnapshots(stored)) &&
Date.now() - stored.createdAtMs > rotateAfterMs &&
Date.now() >= (rotationHoldUntil.get(scope) ?? 0);
@@ -778,15 +776,19 @@ export function createModalSandbox(workspace: WorkspaceStore, opts: ModalSandbox
exportFiles: execExport.exportFiles,
- async persistHomeSnapshot(scopeId: string): Promise<void> {
- const name = sandboxScopeName(prefix, scopeId);
- scopeByName.set(name, scopeId);
- const { session } = await ensureSession(scopeId, name);
- await provisionQueue(scopeId, async () => {
- await assertHydrated(session);
- await homeSnapshots.snapshotHome(scopeId, session);
- });
- },
+ ...(homeSnapshots
+ ? {
+ async persistHomeSnapshot(scopeId: string): Promise<void> {
+ const name = sandboxScopeName(prefix, scopeId);
+ scopeByName.set(name, scopeId);
+ const { session } = await ensureSession(scopeId, name);
+ await provisionQueue(scopeId, async () => {
+ await assertHydrated(session);
+ await homeSnapshots.snapshotHome(scopeId, session);
+ });
+ },
+ }
+ : {}),
async restartComputer(scopeId: string): Promise<void> {
await provisionQueue(scopeId, async () => {
diff --git a/src/sandbox/porter-sandbox.ts b/src/sandbox/porter-sandbox.ts
index 2f5375cba..33631ab36 100644
--- a/src/sandbox/porter-sandbox.ts
+++ b/src/sandbox/porter-sandbox.ts
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
import { NotFoundError } from "porter-sandbox";
import type { WorkspaceLayer } from "../types.ts";
import type { WorkspaceStore } from "../workspace/workspace-store.ts";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import { createKeyedQueue } from "../util/async.ts";
import { swallowAs, errMessage } from "../util/errors.ts";
import {
@@ -71,7 +71,7 @@ export interface PorterSandboxOptions {
apiBaseUrl?: string;
extraTools?: string[];
credentialPaths?: CredentialPathSpec[];
- advisoryLock?: AdvisoryLock;
+ advisoryLock: AdvisoryLock;
client?: PorterClientLike;
onError?: (e: { category: string; code: string; message: string; scopeLabel?: string }) => void;
}
@@ -80,7 +80,7 @@ export const porterScopeSlug = porterSlug;
const bodyName = (slug: string): string => `${slug}-${randomUUID().slice(0, 5)}`;
-export function createPorterSandbox(workspace: WorkspaceStore, opts: PorterSandboxOptions = {}): Sandbox {
+export function createPorterSandbox(workspace: WorkspaceStore, opts: PorterSandboxOptions): Sandbox {
const image = opts.image ?? DEFAULT_PORTER_SANDBOX_IMAGE;
const prefix = opts.namePrefix ?? "qm";
const homeDir = opts.homeDir ?? "/root";
@@ -88,7 +88,7 @@ export function createPorterSandbox(workspace: WorkspaceStore, opts: PorterSandb
const defaultTimeoutSec = opts.defaultTimeoutSec ?? 600;
const workspaceDir = `${homeDir}/${WORKSPACE_BASENAME}`;
const provisionQueue = createKeyedQueue<string>();
- const advisoryLock = opts.advisoryLock ?? createNoopAdvisoryLock();
+ const advisoryLock = opts.advisoryLock;
const egressProxyHost = opts.egressProxyUrl ? new URL(opts.egressProxyUrl).hostname : undefined;
const client: PorterClientLike =
diff --git a/src/sandbox/smolmachines-sandbox.ts b/src/sandbox/smolmachines-sandbox.ts
index 16f3f00a7..dd89b4f7f 100644
--- a/src/sandbox/smolmachines-sandbox.ts
+++ b/src/sandbox/smolmachines-sandbox.ts
@@ -1,8 +1,7 @@
import { randomUUID } from "node:crypto";
import type { WorkspaceStore } from "../workspace/workspace-store.ts";
-import { createMemoryAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import type { DurableMap } from "../persistence/durable-map.ts";
-import { createMemoryMap } from "../persistence/durable-map.ts";
import { fetchWithRetry, sleep } from "../util/async.ts";
import { httpFailure, errMessage, swallowAs } from "../util/errors.ts";
import { shq } from "../util/shell.ts";
@@ -78,8 +77,8 @@ export interface SmolmachinesSandboxOptions extends BlobStagingOptions {
defaultTimeoutSec?: number;
egressProxyUrl?: string;
snapshotIntervalMs?: number;
- store?: DurableMap<StoredSmolmachinesSandbox>;
- advisoryLock?: AdvisoryLock;
+ store: DurableMap<StoredSmolmachinesSandbox>;
+ advisoryLock: AdvisoryLock;
snapshots?: HomeSnapshotStore;
extraTools?: string[];
credentialPaths?: CredentialPathSpec[];
@@ -88,7 +87,7 @@ export interface SmolmachinesSandboxOptions extends BlobStagingOptions {
onError?: (e: { category: string; code: string; message: string; scopeLabel?: string }) => void;
}
-export function createSmolmachinesSandbox(workspace: WorkspaceStore, opts: SmolmachinesSandboxOptions = {}): Sandbox {
+export function createSmolmachinesSandbox(workspace: WorkspaceStore, opts: SmolmachinesSandboxOptions): Sandbox {
if (!opts.token && !opts.fetchImpl) throw new Error("SANDBOX_BACKEND=smolmachines requires SMOLMACHINES_TOKEN");
const fetchImpl = opts.fetchImpl ?? fetch;
const baseUrl = (opts.baseUrl ?? DEFAULT_SMOLMACHINES_BASE_URL).replace(/\/+$/, "");
@@ -101,8 +100,8 @@ export function createSmolmachinesSandbox(workspace: WorkspaceStore, opts: Smolm
};
const defaultTimeoutSec = opts.defaultTimeoutSec ?? 600;
const snapshotIntervalMs = opts.snapshotIntervalMs ?? 0;
- const store = opts.store ?? createMemoryMap<StoredSmolmachinesSandbox>();
- const advisoryLock = opts.advisoryLock ?? createMemoryAdvisoryLock();
+ const store = opts.store;
+ const advisoryLock = opts.advisoryLock;
const lifecycleKey = (scope: string): string => `smolmachines-provision:${prefix}:${scope}`;
const egressProxyHost = opts.egressProxyUrl ? new URL(opts.egressProxyUrl).hostname : undefined;
const network: MachineNetwork = egressProxyHost ? { mode: "allowCidrs", hosts: [egressProxyHost] } : { mode: "open" };
diff --git a/src/sandbox/sprites-sandbox.ts b/src/sandbox/sprites-sandbox.ts
index db25b6256..d61c041c2 100644
--- a/src/sandbox/sprites-sandbox.ts
+++ b/src/sandbox/sprites-sandbox.ts
@@ -2,8 +2,8 @@ import { randomUUID } from "node:crypto";
import { setTimeout as wait } from "node:timers/promises";
import type { Readable } from "node:stream";
import { APIError, SpritesClient, type Checkpoint, type SpriteCheck, type StreamMessage } from "@fly/sprites";
-import { createMemoryMap, type DurableMap } from "../persistence/durable-map.ts";
-import { createMemoryAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
+import type { DurableMap } from "../persistence/durable-map.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import type { WorkspaceStore } from "../workspace/workspace-store.ts";
import { jitteredBackoffMs, retryAfterMs, withAbort, withTimeout } from "../util/async.ts";
import { swallow, errMessage } from "../util/errors.ts";
@@ -131,8 +131,8 @@ export interface SpritesSandboxOptions extends BlobStagingOptions {
memoryMb?: number;
checkpointIntervalMs?: number;
snapshots?: HomeSnapshotStore;
- initializationStore?: DurableMap<{ pending: boolean }>;
- advisoryLock?: AdvisoryLock;
+ initializationStore: DurableMap<{ pending: boolean }>;
+ advisoryLock: AdvisoryLock;
extraTools?: string[];
credentialPaths?: CredentialPathSpec[];
connectorSdk?: () => Promise<ConnectorSdkBundle>;
@@ -146,13 +146,13 @@ interface RawExec {
stderr: Buffer;
}
-export function createSpritesSandbox(workspace: WorkspaceStore, opts: SpritesSandboxOptions = {}): Sandbox {
+export function createSpritesSandbox(workspace: WorkspaceStore, opts: SpritesSandboxOptions): Sandbox {
if (!opts.token) throw new Error("SANDBOX_BACKEND=sprites requires SPRITES_TOKEN");
const client = new SpritesClient(opts.token, opts.baseUrl ? { baseURL: opts.baseUrl } : {});
const sprite = (name: string) => client.sprite(name);
const prefix = opts.namePrefix ?? "qm";
- const initializationStore = opts.initializationStore ?? createMemoryMap<{ pending: boolean }>();
- const advisoryLock = opts.advisoryLock ?? createMemoryAdvisoryLock();
+ const initializationStore = opts.initializationStore;
+ const advisoryLock = opts.advisoryLock;
const withLifecycle = <T>(name: string, fn: () => Promise<T>): Promise<T> =>
advisoryLock.withLock(`sprites-lifecycle:${name}`, fn);
const requireInitialized = async (name: string): Promise<void> => {
diff --git a/src/sandbox/superserve-sandbox.ts b/src/sandbox/superserve-sandbox.ts
index ab73a219d..cd40e5c80 100644
--- a/src/sandbox/superserve-sandbox.ts
+++ b/src/sandbox/superserve-sandbox.ts
@@ -4,8 +4,7 @@ import { createHash, randomUUID } from "node:crypto";
import type { WorkspaceLayer } from "../types.ts";
import type { WorkspaceStore } from "../workspace/workspace-store.ts";
import type { DurableMap } from "../persistence/durable-map.ts";
-import { createNoopAdvisoryLock, type AdvisoryLock } from "../persistence/advisory-lock.ts";
-import { createMemoryMap } from "../persistence/durable-map.ts";
+import type { AdvisoryLock } from "../persistence/advisory-lock.ts";
import { createKeyedQueue } from "../util/async.ts";
import { swallowAs, errMessage } from "../util/errors.ts";
import { shq } from "../util/shell.ts";
@@ -85,7 +84,7 @@ const CONFIG_EPOCH_LOCK = "superserve-config-epoch";
export function createConfigEpochResolver(
store: DurableMap<StoredConfigEpoch>,
generationKey: string,
- lock: AdvisoryLock = createNoopAdvisoryLock(),
+ lock: AdvisoryLock,
): () => Promise<number> {
let pending: Promise<number> | undefined;
const claim = (): Promise<number> =>
@@ -113,15 +112,15 @@ export interface SuperserveSandboxOptions extends BlobStagingOptions {
homeDir?: string;
idlePauseSec?: number;
keepWarmSec?: number;
- configEpoch?: number | (() => Promise<number>);
+ configEpoch: number | (() => Promise<number>);
retentionSec?: number;
egressAllow?: string[];
egressDeny?: string[];
extraTools?: string[];
credentialPaths?: CredentialPathSpec[];
layerToolFiles?: () => readonly LayerInstallFile[];
- store?: DurableMap<StoredSuperserveSandbox>;
- advisoryLock?: AdvisoryLock;
+ store: DurableMap<StoredSuperserveSandbox>;
+ advisoryLock: AdvisoryLock;
onError?: (e: { category: string; code: string; message: string; scopeLabel?: string }) => void;
}
@@ -150,8 +149,8 @@ export function createSuperserveSandbox(workspace: WorkspaceStore, opts: Superse
...(opts.egressDeny?.length ? { denyOut: opts.egressDeny } : {}),
}
: undefined;
- const store = opts.store ?? createMemoryMap<StoredSuperserveSandbox>();
- const advisoryLock = opts.advisoryLock ?? createNoopAdvisoryLock();
+ const store = opts.store;
+ const advisoryLock = opts.advisoryLock;
const lockKey = (scope: string): string => `superserve-provision:${scope}`;
const provisionQueue = createKeyedQueue<string>();
@@ -178,9 +177,8 @@ export function createSuperserveSandbox(workspace: WorkspaceStore, opts: Superse
.digest("hex")
.slice(0, 16);
- const bootEpoch = Date.now();
const configEpoch = async (): Promise<number> =>
- typeof opts.configEpoch === "function" ? opts.configEpoch() : (opts.configEpoch ?? bootEpoch);
+ typeof opts.configEpoch === "function" ? opts.configEpoch() : opts.configEpoch;
void configEpoch().catch(swallowAs("superserve-sandbox: claim config generation", undefined));
const scopeMetadata = async (name: string): Promise<Record<string, string>> => ({
[SUPERSERVE_METADATA.epoch]: String(await configEpoch()),
diff --git a/src/skills/skill-sync-engine.ts b/src/skills/skill-sync-engine.ts
index ba66d45bb..b4c9f9720 100644
--- a/src/skills/skill-sync-engine.ts
+++ b/src/skills/skill-sync-engine.ts
@@ -1,6 +1,6 @@
import type { SkillPackStore } from "./skill-pack-store.ts";
import type { SkillPackFetcher } from "./pack-fetcher.ts";
-import { createNoopLeaderLease, type LeaderLease } from "../persistence/leader-lease.ts";
+import type { LeaderLease } from "../persistence/leader-lease.ts";
import { createSweeper } from "../util/sweeper.ts";
import { errMessage, reportFailureAs } from "../util/errors.ts";
@@ -17,11 +17,11 @@ export interface SkillSyncDeps {
packs: SkillPackStore;
fetcher: SkillPackFetcher;
reconcile: (packId: string) => Promise<unknown>;
- leaderLease?: LeaderLease;
+ leaderLease: LeaderLease;
}
export function createSkillSyncEngine(deps: SkillSyncDeps): SkillSyncEngine {
- const leaderLease = deps.leaderLease ?? createNoopLeaderLease();
+ const leaderLease = deps.leaderLease;
async function syncOne(packId: string): Promise<void> {
const pack = await deps.packs.get(packId);
diff --git a/src/wake/sweep.ts b/src/wake/sweep.ts
index d4a3851d6..e28c75d9c 100644
--- a/src/wake/sweep.ts
+++ b/src/wake/sweep.ts
@@ -1,6 +1,5 @@
import { createSweeper, type Sweeper } from "../util/sweeper.ts";
import type { LeaderLease } from "../persistence/leader-lease.ts";
-import { createNoopLeaderLease } from "../persistence/leader-lease.ts";
const SWEEP_LEASE_KEY = "wake:sweep";
@@ -11,7 +10,7 @@ export interface SweepSource {
export interface WakeSweepOptions {
intervalMs: number;
- leaderLease?: LeaderLease;
+ leaderLease: LeaderLease;
}
export interface WakeSweep {
@@ -21,7 +20,7 @@ export interface WakeSweep {
}
export function createWakeSweep(source: SweepSource, opts: WakeSweepOptions): WakeSweep {
- const leaderLease = opts.leaderLease ?? createNoopLeaderLease();
+ const leaderLease = opts.leaderLease;
const sweep = async (): Promise<{ swept: number; fresh: number }> => {
const targets = await source.engagedSessions();
diff --git a/src/wiring.ts b/src/wiring.ts
index 632cd7ec0..28d6d2ce1 100644
--- a/src/wiring.ts
+++ b/src/wiring.ts
@@ -1093,9 +1093,7 @@ export function buildApp(
.digest("hex")
.slice(0, 32);
return createSuperserveSandbox(workspace, {
- configEpoch:
- ss.configGeneration ??
- (pgArtifactMap ? createConfigEpochResolver(superserveEpochs, generationKey, advisoryLock) : 0),
+ configEpoch: ss.configGeneration ?? createConfigEpochResolver(superserveEpochs, generationKey, advisoryLock),
client: createSdkSuperserveClient({
apiKey: ss.apiKey,
...(ss.baseUrl ? { baseUrl: ss.baseUrl } : {}),
@@ -2640,7 +2638,7 @@ export function buildApp(
skipFire: async (cron) => (await memoryTidy.skipFire(cron)) ?? suggestedActivities.skipFire(cron),
deleteCron: (id) => app.deleteCron(id),
requireQueueStart: Boolean(config.backgroundDeploymentId),
- lock: advisoryLock,
+ advisoryLock,
crons,
deliveries,
idempotency,
diff --git a/test/admin-agent-capability.test.ts b/test/admin-agent-capability.test.ts
index 31dabfa28..09349a5e9 100644
--- a/test/admin-agent-capability.test.ts
+++ b/test/admin-agent-capability.test.ts
@@ -24,6 +24,7 @@ import {
} from "../src/auth/capability-token.ts";
import { testConfig } from "./support/test-config.ts";
import { mintSignedPayload } from "../src/auth/signed-token.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const SECRET = "agent-admin-test-secret".repeat(3);
const ORG = scopeId("org", "default-org");
@@ -45,6 +46,7 @@ function start(withConfig = true) {
],
);
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/admin-keychain.test.ts b/test/admin-keychain.test.ts
index 9fe90e355..017736e26 100644
--- a/test/admin-keychain.test.ts
+++ b/test/admin-keychain.test.ts
@@ -13,10 +13,12 @@ import { deriveConnectorKey } from "../src/connectors/connector-client-store.ts"
import { createMemoryMap } from "../src/persistence/durable-map.ts";
import { scopeId, type TurnRequest } from "../src/types.ts";
import { testConfig } from "./support/test-config.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
function start() {
const built = buildApp(testConfig({ dataDir: mkdtempSync(join(tmpdir(), "admin-keychain-")) }));
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/agent-computer-profile.test.ts b/test/agent-computer-profile.test.ts
index ccadbe6d5..19151922e 100644
--- a/test/agent-computer-profile.test.ts
+++ b/test/agent-computer-profile.test.ts
@@ -9,6 +9,9 @@ import { createSpritesSandbox } from "../src/sandbox/sprites-sandbox.ts";
import { createAwsSandbox } from "../src/sandbox/aws-sandbox.ts";
import { effectiveEgressEnforcement } from "../src/sandbox/sandbox.ts";
import { installFakeMicrovm } from "./support/fake-microvm.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
async function withWorkspace<T>(fn: (dir: string) => Promise<T> | T): Promise<T> {
const dir = await mkdtemp(join(tmpdir(), "agent-computer-profile-"));
@@ -22,6 +25,8 @@ async function withWorkspace<T>(fn: (dir: string) => Promise<T> | T): Promise<T>
function awsSandbox(extraTools: string[]) {
const fake = installFakeMicrovm();
return createAwsSandbox(createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "aws-profile-"))), {
+ store: createMemoryMap(),
+ ...singleProcessDeps(),
region: "us-west-2",
imageIdentifier: "img",
s3Bucket: "bucket",
@@ -35,7 +40,11 @@ function awsSandbox(extraTools: string[]) {
test("the sprites sandbox declares the Agent Computer contract (persistent per-scope computer)", async () => {
await withWorkspace(async (dir) => {
const workspace = createLocalWorkspaceStore(dir);
- const sprites = createSpritesSandbox(workspace, { token: "test-token" });
+ const sprites = createSpritesSandbox(workspace, {
+ initializationStore: createMemoryMap(),
+ advisoryLock: createMemoryAdvisoryLock(),
+ token: "test-token",
+ });
const { spec, ...contract } = sprites.profile;
assert.deepEqual(contract, {
@@ -71,6 +80,8 @@ test("a layer that advertises a tool removes it from notInstalled (no install/no
test("egress enforcement is effective only when core can mint a reachable proxy token", async () => {
await withWorkspace((dir) => {
const sprites = createSpritesSandbox(createLocalWorkspaceStore(dir), {
+ initializationStore: createMemoryMap(),
+ advisoryLock: createMemoryAdvisoryLock(),
token: "test-token",
egressProxyUrl: "https://egress-proxy.example.com",
});
diff --git a/test/agent37-sandbox.test.ts b/test/agent37-sandbox.test.ts
index e357d0218..7fa05f0a6 100644
--- a/test/agent37-sandbox.test.ts
+++ b/test/agent37-sandbox.test.ts
@@ -14,6 +14,7 @@ import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
import { installFakeAgent37, FAKE_AGENT37_API_KEY, type FakeAgent37 } from "./support/fake-agent37.ts";
import { NonRetryableTurnError } from "../src/core/turn-error.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
let fake: FakeAgent37;
let sandbox: Sandbox;
@@ -22,6 +23,7 @@ const layers = [{ scopeId: scope, mountPath: "/", mode: "rw" as const }];
function make(extra: Record<string, unknown> = {}): Sandbox {
return createAgent37Sandbox(createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "a37-ws-"))), {
+ ...singleProcessDeps(),
apiKey: FAKE_AGENT37_API_KEY,
namePrefix: "qmt",
fetchImpl: fake.fetchImpl,
diff --git a/test/app-page-views.test.ts b/test/app-page-views.test.ts
index 7771a0c09..b492bcdc1 100644
--- a/test/app-page-views.test.ts
+++ b/test/app-page-views.test.ts
@@ -17,6 +17,7 @@ import { createMemorySessionStore } from "../src/sessions/memory-session-store.t
import { scopeId } from "../src/types.ts";
import type { FeatureFlagStore } from "../src/feature-flags.ts";
import type { AppPageView, AppPageViewLog } from "../src/deploy/page-views.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const SESSION_SECRET = "portal-session-secret";
const LOGIN_URL = "https://portal.example.com";
@@ -56,6 +57,7 @@ async function harness(log: AppPageViewLog) {
const upstreamPort = (upstream.address() as AddressInfo).port;
const acl = createAclStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
externalSharingAllowed: async () => true,
deployStore: createDeployStore(),
provider: {
diff --git a/test/aws-deploy-provider.test.ts b/test/aws-deploy-provider.test.ts
index dbf875870..99b5431a4 100644
--- a/test/aws-deploy-provider.test.ts
+++ b/test/aws-deploy-provider.test.ts
@@ -14,6 +14,7 @@ import {
import { createMemoryMap } from "../src/persistence/durable-map.ts";
import type { Deployment, DeploymentVersion } from "../src/deploy/deploy-store.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const REGION = "us-west-2";
@@ -182,6 +183,7 @@ function provider(
extra: Record<string, unknown> = {},
) {
return createAwsDeployProvider({
+ ...singleProcessDeps(),
region: REGION,
imageIdentifier: "qm-microvm-sandbox",
appPort: 8081,
diff --git a/test/aws-sandbox.test.ts b/test/aws-sandbox.test.ts
index 4aa470598..a4aba50d0 100644
--- a/test/aws-sandbox.test.ts
+++ b/test/aws-sandbox.test.ts
@@ -10,10 +10,14 @@ import { sleep } from "../src/util/async.ts";
import { scopeId } from "../src/types.ts";
import { createMemoryBlobTransferStore } from "../src/persistence/blob-transfer.ts";
import { installFakeMicrovm, type FakeMicrovm } from "./support/fake-microvm.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
function makeSandbox(fake: FakeMicrovm, opts: Record<string, unknown> = {}) {
const dir = mkdtempSync(join(tmpdir(), "aws-ws-"));
return createAwsSandbox(createLocalWorkspaceStore(dir), {
+ store: createMemoryMap(),
+ ...singleProcessDeps(),
region: "us-west-2",
imageIdentifier: "img",
s3Bucket: "bucket",
diff --git a/test/composio-route.test.ts b/test/composio-route.test.ts
index 54fa87fab..72efe7db7 100644
--- a/test/composio-route.test.ts
+++ b/test/composio-route.test.ts
@@ -12,9 +12,11 @@ import { deriveConnectorKey } from "../src/connectors/connector-client-store.ts"
import { createAclStore } from "../src/acl/acl-store.ts";
import { scopeId } from "../src/types.ts";
import { orgId } from "../src/config.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
function fixture() {
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/composio-twitter-media.test.ts b/test/composio-twitter-media.test.ts
index 221841f42..6e5b0654e 100644
--- a/test/composio-twitter-media.test.ts
+++ b/test/composio-twitter-media.test.ts
@@ -10,6 +10,7 @@ import { createKeychain } from "../src/credentials/keychain.ts";
import { createMemoryMap } from "../src/persistence/durable-map.ts";
import { deriveConnectorKey } from "../src/connectors/connector-client-store.ts";
import { orgId } from "../src/config.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const PNG = Buffer.concat([
Buffer.from("89504e470d0a1a0a0000000d49484452000000010000000108020000009077" + "53de", "hex"),
@@ -45,6 +46,7 @@ async function fixture() {
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
+ lock: createMemoryAdvisoryLock(),
key: deriveConnectorKey("composio-test"),
});
await keychain.save({ ownerId: "alice", service: "composio", envKey: "COMPOSIO_API_KEY", secret: "private-key" });
diff --git a/test/config.test.ts b/test/config.test.ts
index 5a52d2434..072559ef4 100644
--- a/test/config.test.ts
+++ b/test/config.test.ts
@@ -23,6 +23,8 @@ const productionEnv = {
PORTAL_IDENTITY_SECRET: "portal",
CONNECTOR_SECRET_KEY: "connector-secret-0123456789abcdef",
SANDBOX_BACKEND: "local",
+ DATABASE_URL: "postgres://qm@localhost/qm",
+ SESSION_STORE: "postgres",
} as const;
test("Sprites proxy transition URLs are optional and parsed independently of the primary", () => {
@@ -295,6 +297,25 @@ test("sandbox backend is parsed once before production backend guards", () => {
);
});
+test("production refuses to boot on in-memory sessions, runs, approvals, audit, locks and leases", () => {
+ const { DATABASE_URL: _databaseUrl, ...noDatabase } = productionEnv;
+ assert.throws(
+ () => loadConfig(noDatabase),
+ /missing or insecure required core secrets: DATABASE_URL \(.*resident disk\)/,
+ );
+ const { SESSION_STORE: _sessionStore, ...memorySessions } = productionEnv;
+ assert.throws(() => loadConfig(memorySessions), /production requires SESSION_STORE=postgres/);
+ assert.throws(
+ () => loadConfig({ ...productionEnv, RUN_STORE: "memory" }),
+ /production requires SESSION_STORE=postgres/,
+ );
+ assert.doesNotThrow(() => loadConfig({ ...productionEnv, RUN_STORE: "postgres" }));
+ assert.doesNotThrow(
+ () => loadConfig({ SANDBOX_BACKEND: "local" }),
+ "a single-process dev instance needs no durable store",
+ );
+});
+
test("production refuses missing, placeholder, or weak signing keys", () => {
assert.throws(
() => loadConfig({ NODE_ENV: "production" }),
@@ -461,23 +482,6 @@ test("SANDBOX_BACKEND: unset defaults to local (dev only); the retired secondary
}).sandboxBackend,
"superserve",
);
- const superserveProd = {
- ...productionEnv,
- SANDBOX_BACKEND: "superserve",
- SUPERSERVE_TEMPLATE: "qm-agent-1.0.0",
- SUPERSERVE_API_KEY: "ss_live_k",
- };
- assert.throws(
- () => loadConfig(superserveProd),
- /superserve sandbox backend requires DATABASE_URL in production/,
- "without a durable store the generation and provisioning lock are per-process",
- );
- assert.throws(
- () => loadConfig({ ...superserveProd, SANDBOX_BACKEND: "local" }),
- /superserve sandbox backend requires DATABASE_URL in production/,
- "the requirement follows the credentials that enable it, not just the primary backend",
- );
- assert.doesNotThrow(() => loadConfig({ ...superserveProd, DATABASE_URL: "postgres://qm@localhost/qm" }));
assert.doesNotThrow(
() =>
loadConfig({
diff --git a/test/connector-default-slot.test.ts b/test/connector-default-slot.test.ts
index c36bddc93..65893f5d9 100644
--- a/test/connector-default-slot.test.ts
+++ b/test/connector-default-slot.test.ts
@@ -3,11 +3,13 @@ import assert from "node:assert/strict";
import { createKeychain, type KeychainCredential } from "../src/credentials/keychain.ts";
import { createMemoryMap } from "../src/persistence/durable-map.ts";
import { deriveConnectorKey } from "../src/connectors/connector-client-store.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const KEY = deriveConnectorKey("test-connector-key-aaaaaaaaaaaaaaaa");
function makeKeychain() {
return createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap<KeychainCredential>(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/connectors.test.ts b/test/connectors.test.ts
index d5eb953e9..1aa4ec7cf 100644
--- a/test/connectors.test.ts
+++ b/test/connectors.test.ts
@@ -16,6 +16,7 @@ import {
type DurableMapSelect,
} from "../src/persistence/durable-map.ts";
import { oauthRevoke } from "../src/api/routes/connectors.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const KEY = deriveConnectorKey("test-connector-key-aaaaaaaaaaaaaaaa");
@@ -28,6 +29,7 @@ function makeKeychain(
} = {},
) {
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: opts.creds ?? createMemoryMap<KeychainCredential>(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/context-compaction.test.ts b/test/context-compaction.test.ts
index d0dfc172e..89beb357f 100644
--- a/test/context-compaction.test.ts
+++ b/test/context-compaction.test.ts
@@ -41,6 +41,7 @@ import type { SessionStore } from "../src/sessions/session-store.ts";
import { contextSummaryPayload, createContextSummaryPayload } from "../src/sessions/session-store.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
import { scopeId, type Conversation, type Principal, type SessionEntry } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
const tokensOf = (...texts: string[]): number => texts.reduce((n, t) => n + countTokens(t), 0);
@@ -115,6 +116,7 @@ function buildOrchestrator(
const sessions = swarm?.sessions ?? createMemorySessionStore();
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "cc-")));
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "cc-deploy"),
@@ -122,6 +124,7 @@ function buildOrchestrator(
acl,
});
const orch = createOrchestrator({
+ ...singleProcessDeps(),
config,
identity: createIdentityService(),
resolution: createResolutionService(ORG, config, acl),
diff --git a/test/cron-credential-retry.test.ts b/test/cron-credential-retry.test.ts
index 8aedc3b28..369fb9d7e 100644
--- a/test/cron-credential-retry.test.ts
+++ b/test/cron-credential-retry.test.ts
@@ -9,6 +9,7 @@ import { createKeychain, type KeychainAsk } from "../src/credentials/keychain.ts
import { deriveConnectorKey } from "../src/connectors/connector-client-store.ts";
import { createMemoryMap } from "../src/persistence/durable-map.ts";
import type { TurnRequest, TurnResult } from "../src/types.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
async function fixture(run: (request: TurnRequest) => Promise<TurnResult>) {
const crons = createCronStore();
@@ -116,6 +117,7 @@ test("a concurrent sweep cannot mark an in-flight busy resume notified before it
const asks = createMemoryMap<KeychainAsk>();
await asks.put(f.ask.id, f.ask);
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks,
diff --git a/test/cron-queue.test.ts b/test/cron-queue.test.ts
index 8a337d1f6..a03a5cc4b 100644
--- a/test/cron-queue.test.ts
+++ b/test/cron-queue.test.ts
@@ -9,6 +9,7 @@ import { createIdempotencyStore, type IdempotencyRecord } from "../src/idempoten
import { createIdentityService } from "../src/identity/identity-service.ts";
import { createPostgresMapFactory } from "../src/persistence/durable-map.ts";
import { scopeId, type Cron, type TurnRequest, type TurnResult } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const URL = process.env.DATABASE_URL;
const skip = URL ? false : "set DATABASE_URL (a Postgres) to run the cron queue tests";
@@ -41,6 +42,7 @@ function instance(calls: TurnRequest[], turnMs = 0, fires?: CronFireStore): { sc
return { status: "ok", reply: "QUEUE-OUTPUT" };
};
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(maps.map<IdempotencyRecord>(IDEM_TABLE)),
diff --git a/test/cron-scheduler.test.ts b/test/cron-scheduler.test.ts
index 0b14b915c..680e963e3 100644
--- a/test/cron-scheduler.test.ts
+++ b/test/cron-scheduler.test.ts
@@ -14,6 +14,7 @@ import { createMemoryMap } from "../src/persistence/durable-map.ts";
import type { Cron } from "../src/types.ts";
import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
import type { CronFireJob, CronJobQueue } from "../src/cron/job-queue.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function fakeLease(isLeader: () => boolean): LeaderLease {
return {
@@ -38,6 +39,7 @@ function harness(
return { status: "ok", reply };
};
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries,
idempotency: createIdempotencyStore(),
@@ -336,6 +338,7 @@ test("only the leader instance fires due crons on tick (non-leader skips)", asyn
};
let leader = false;
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries,
idempotency,
@@ -549,6 +552,7 @@ test("a cron whose attempt marker cannot persist is held back and cannot starve
},
};
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons: flaky,
deliveries,
idempotency: createIdempotencyStore(),
@@ -583,6 +587,7 @@ test("capped rotation survives a scheduler restart mid-cycle", async () => {
};
const mk = () =>
createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries,
idempotency: createIdempotencyStore(),
@@ -725,6 +730,7 @@ test("cron fires do not replay prior sessions or inline prior fire context", asy
return { status: "ok", reply: replies[sessionIds.length - 1] ?? "ok", sessionId: session.id };
};
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -763,6 +769,7 @@ test("an idempotency-skipped cron fire does not create fire log history", async
const crons = createCronStore();
const calls: TurnRequest[] = [];
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: {
@@ -837,6 +844,7 @@ test("a failing cron fire is logged, not swallowed", async (t) => {
});
const crons = createCronStore();
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -874,6 +882,7 @@ test("queue mode: fires claim the slot before running, and stale or lost claims
let onFire: ((job: { cronId: string; scheduledAt: number }) => Promise<void>) | undefined;
const enqueued: Array<{ cronId: string; scheduledAt: number }> = [];
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -937,11 +946,12 @@ for (const queued of [false, true]) {
async stop() {},
};
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
identity: createIdentityService(),
- lock: createMemoryAdvisoryLock(),
+ advisoryLock: createMemoryAdvisoryLock(),
now: () => clock,
...(queued ? { jobQueue } : {}),
run: async (req) => {
@@ -1037,12 +1047,13 @@ test("queue mode: concurrent reconciliation cannot consume an overdue slot while
const enqueued: CronFireJob[] = [];
const calls: TurnRequest[] = [];
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
identity: createIdentityService(),
now: () => clock,
- lock: {
+ advisoryLock: {
...mutex,
async tryWithLock(key, fn) {
const gate = gates[attempts++];
@@ -1106,6 +1117,7 @@ test("queue mode: while the queue runs, the interval scheduler's leader lease is
t.mock.timers.enable({ apis: ["setInterval"] });
const heldKeys: string[] = [];
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons: createCronStore(),
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -1142,6 +1154,7 @@ test("queue mode: an authz-failed fire disables the cron but gives the slot back
let onFire: ((job: { cronId: string; scheduledAt: number }) => Promise<void>) | undefined;
const calls: TurnRequest[] = [];
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -1374,6 +1387,7 @@ test("a one-shot whose session is busy is deferred, stays enabled, and fires onc
const calls: TurnRequest[] = [];
let clock = 1000;
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -1423,6 +1437,7 @@ test("a fire that is still busy ten minutes past its slot gives up: consumed and
const crons = createCronStore();
const calls: TurnRequest[] = [];
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -1455,6 +1470,7 @@ test("queue mode: a busy fire releases its slot and is re-queued to run after th
let onFire: ((job: { cronId: string; scheduledAt: number; notBefore?: number }) => Promise<void>) | undefined;
const enqueued: Array<{ cronId: string; scheduledAt: number; notBefore?: number }> = [];
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -1514,6 +1530,7 @@ test("scheduler stop waits for delayed queue startup and supports an awaited res
let starts = 0;
let stops = 0;
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons: createCronStore(),
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -1551,6 +1568,7 @@ test("scheduler cannot resume after uncertain queue shutdown until a stop retry
let starts = 0;
let stops = 0;
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons: createCronStore(),
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -1585,6 +1603,7 @@ test("scheduler relinquishes queue claims before a long turn drains and preserve
let claimsStopped = false;
let queueClosed = false;
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -1669,6 +1688,7 @@ test("scheduler resumes new queue claims while an older admitted turn remains al
let starts = 0;
let closed = false;
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
idempotency: createIdempotencyStore(),
@@ -1747,6 +1767,7 @@ test("manual cron preparation and detached fire retain admission across pause",
return get(id);
};
const scheduler = createScheduler({
+ ...singleProcessDeps(),
admittedWork: work,
crons,
deliveries: createDeliveryStore(),
diff --git a/test/deploy-access.test.ts b/test/deploy-access.test.ts
index 2eaf4478d..09eb28572 100644
--- a/test/deploy-access.test.ts
+++ b/test/deploy-access.test.ts
@@ -21,6 +21,7 @@ import {
} from "../src/slack/deploy-access.ts";
import type { CapabilityClaims } from "../src/auth/capability-token.ts";
import { scopeId, type ActorAssertion, type Permission } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const owner = "[email protected]";
const requester = "[email protected]";
@@ -50,6 +51,7 @@ async function fixture(t: { after(fn: () => void): void }) {
})),
);
const deploy = createDeployService({
+ ...singleProcessDeps(),
canManageEmail: async (email) => (await directory.get(email))?.type === "internal",
deliveries,
deployAppsDomain: "apps.example.com",
diff --git a/test/deploy-always-on.test.ts b/test/deploy-always-on.test.ts
index 93f150079..5ba1ad1e1 100644
--- a/test/deploy-always-on.test.ts
+++ b/test/deploy-always-on.test.ts
@@ -9,6 +9,7 @@ import { createAclStore } from "../src/acl/acl-store.ts";
import type { DeployProvider } from "../src/deploy/deploy-provider.ts";
import type { DeployEndpoint } from "../src/deploy/deploy-store.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function svc(
opts: {
@@ -44,6 +45,7 @@ function svc(
: {}),
};
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider,
auditLog: { record() {}, events: async () => [], tail: async () => [] },
@@ -140,6 +142,7 @@ test("alwaysOn is visible to the provider at first launch (not applied after the
destroy: async () => {},
};
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider,
auditLog: { record() {}, events: async () => [], tail: async () => [] },
@@ -173,6 +176,7 @@ test("reaper re-checks alwaysOn under the deploy lock (no stale-snapshot destroy
},
};
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider,
auditLog: { record() {}, events: async () => [], tail: async () => [] },
diff --git a/test/deploy-app-only.test.ts b/test/deploy-app-only.test.ts
index 28517046f..baf1a550a 100644
--- a/test/deploy-app-only.test.ts
+++ b/test/deploy-app-only.test.ts
@@ -18,6 +18,7 @@ import { deriveKey, seal } from "../plugins/portal/src/session.ts";
import { scopeId } from "../src/types.ts";
import { deployRef, encodeRef } from "../src/acl/resource-ref.ts";
import type { FeatureFlagStore } from "../src/feature-flags.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const externalSharingOn = { enabled: async () => true } as unknown as FeatureFlagStore;
@@ -45,6 +46,7 @@ test("app-only gateway checks exact current personal read grants without inherit
await new Promise<void>((resolve) => upstream.listen(0, "127.0.0.1", resolve));
const acl = createAclStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
externalSharingAllowed: async () => true,
deployStore: createDeployStore({ git: { repoRoot: join(dir, "repos") } }),
provider: {
diff --git a/test/deploy-app-shell.test.ts b/test/deploy-app-shell.test.ts
index d375059c8..1d826a5a6 100644
--- a/test/deploy-app-shell.test.ts
+++ b/test/deploy-app-shell.test.ts
@@ -19,6 +19,7 @@ import { scopeId } from "../src/types.ts";
import { createMemoryMap } from "../src/persistence/durable-map.ts";
import { createFeatureFlagStore, type FeatureFlagRecord } from "../src/feature-flags.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const auditLog = { record() {}, events: async () => [], tail: async () => [] };
const GATE_SECRET = "gate-secret";
@@ -29,6 +30,7 @@ function appServingUpstream(upstreamPort: number) {
const acl = createAclStore();
const directory = createDirectoryStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/deploy-app-size.test.ts b/test/deploy-app-size.test.ts
index fc4b81c56..1b4b80314 100644
--- a/test/deploy-app-size.test.ts
+++ b/test/deploy-app-size.test.ts
@@ -8,12 +8,14 @@ import { createDeployStore } from "../src/deploy/deploy-store.ts";
import { createDeployService } from "../src/deploy/deploy-service.ts";
import { createAclStore } from "../src/acl/acl-store.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function service(maxAppBytes?: number) {
const dir = mkdtempSync(join(tmpdir(), "deploy-app-size-"));
let applies = 0;
const store = createDeployStore({ git: { repoRoot: join(dir, "repos") } });
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: store,
provider: {
profile: { managedScaleToZero: false, ...(maxAppBytes ? { maxAppBytes } : {}) },
diff --git a/test/deploy-artifact-image.test.ts b/test/deploy-artifact-image.test.ts
index bb7eba424..566569d62 100644
--- a/test/deploy-artifact-image.test.ts
+++ b/test/deploy-artifact-image.test.ts
@@ -13,6 +13,7 @@ import { createDeployService, type DeployService } from "../src/deploy/deploy-se
import type { DeployReconcileInput } from "../src/deploy/deploy-provider.ts";
import { createAclStore } from "../src/acl/acl-store.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
interface ProviderProbe {
appliedImages: Array<string | undefined>;
@@ -22,6 +23,7 @@ function flyLikeService(): { deploy: DeployService; deployStore: DeployStore; pr
const deployStore = createDeployStore();
const probe: ProviderProbe = { appliedImages: [] };
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
acl: createAclStore(),
auditLog: { record() {}, events: async () => [], tail: async () => [] },
@@ -93,6 +95,7 @@ test("rollback reuses the stored image — the provider gets the recorded ref, n
test("a runtime-mount provider (no image) leaves versions image-less — Docker behavior unchanged", async () => {
const deployStore = createDeployStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
acl: createAclStore(),
auditLog: { record() {}, events: async () => [], tail: async () => [] },
@@ -120,6 +123,7 @@ test("a reconcile-capable provider receives the git diff and marks the applied v
const deployStore = createDeployStore();
const reconciles: DeployReconcileInput[] = [];
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
acl: createAclStore(),
auditLog: { record() {}, events: async () => [], tail: async () => [] },
@@ -170,6 +174,7 @@ test("applied version is marked only after endpoint metadata is persisted", asyn
},
};
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
acl: createAclStore(),
auditLog: { record() {}, events: async () => [], tail: async () => [] },
@@ -199,6 +204,7 @@ test("a failed redeploy does not move the hosted git current ref", async () => {
const deployStore = createDeployStore();
let applies = 0;
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
acl: createAclStore(),
auditLog: { record() {}, events: async () => [], tail: async () => [] },
diff --git a/test/deploy-concurrency.test.ts b/test/deploy-concurrency.test.ts
index 5c870a2e6..3901754c2 100644
--- a/test/deploy-concurrency.test.ts
+++ b/test/deploy-concurrency.test.ts
@@ -10,6 +10,7 @@ import type { LeaderLease } from "../src/persistence/leader-lease.ts";
import type { AdvisoryLock } from "../src/persistence/advisory-lock.ts";
import type { DeployProvider } from "../src/deploy/deploy-provider.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const nonLeaderLease: LeaderLease = {
async hold() {
@@ -28,6 +29,7 @@ function svc(opts: { lease?: LeaderLease; lock?: AdvisoryLock; managed?: boolean
},
};
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider,
auditLog: { record() {}, events: async () => [], tail: async () => [] },
@@ -121,6 +123,7 @@ test("withDeployLock: same-instance lifecycle ops still serialize (no overlap)",
destroy: async () => {},
};
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider,
auditLog: { record() {}, events: async () => [], tail: async () => [] },
diff --git a/test/deploy-createdin-manage.test.ts b/test/deploy-createdin-manage.test.ts
index 5c97b2cac..5e603aba1 100644
--- a/test/deploy-createdin-manage.test.ts
+++ b/test/deploy-createdin-manage.test.ts
@@ -16,6 +16,7 @@ import { createCanReadScope, createCanWriteScope } from "../src/resolution/scope
import { createMemorySessionStore } from "../src/sessions/memory-session-store.ts";
import { mintCapabilityToken, CAPABILITY_TTL_MS, CONTROL_PLANE_AUD } from "../src/auth/capability-token.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const SECRET = "deploy-createdin-secret".repeat(3);
const CH = "CBUILT";
@@ -27,6 +28,7 @@ async function fixture() {
const directory: DirectoryStore = createDirectoryStore();
const sessions = createMemorySessionStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/deploy-embed-ancestors.test.ts b/test/deploy-embed-ancestors.test.ts
index 1438539b3..67a93f46d 100644
--- a/test/deploy-embed-ancestors.test.ts
+++ b/test/deploy-embed-ancestors.test.ts
@@ -7,10 +7,12 @@ import { createDeployStore } from "../src/deploy/deploy-store.ts";
import { createDeployService } from "../src/deploy/deploy-service.ts";
import { createAclStore } from "../src/acl/acl-store.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function svc() {
const deployStore = createDeployStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/deploy-environment.test.ts b/test/deploy-environment.test.ts
index 9e8007ede..2a923eb24 100644
--- a/test/deploy-environment.test.ts
+++ b/test/deploy-environment.test.ts
@@ -9,6 +9,7 @@ import { createAclStore } from "../src/acl/acl-store.ts";
import { scopeId } from "../src/types.ts";
import type { DeployProvider } from "../src/deploy/deploy-provider.ts";
import type { Deployment, DeploymentVersion } from "../src/deploy/deploy-store.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const tmp = () => mkdtempSync(join(tmpdir(), "deployment-env-"));
function svc(deploymentEnv?: (deployment: Deployment) => Promise<Record<string, string>>) {
@@ -23,6 +24,7 @@ function svc(deploymentEnv?: (deployment: Deployment) => Promise<Record<string,
destroy: async () => {},
};
const service = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider,
auditLog: { record() {}, events: async () => [], tail: async () => [] },
diff --git a/test/deploy-git-rw.test.ts b/test/deploy-git-rw.test.ts
index 471f5c023..a9f485234 100644
--- a/test/deploy-git-rw.test.ts
+++ b/test/deploy-git-rw.test.ts
@@ -19,6 +19,7 @@ import { createMemorySessionStore } from "../src/sessions/memory-session-store.t
import { mintDeployGitAccess, verifyDeployGitAccess } from "../src/deploy/access-token.ts";
import { mintCapabilityToken, CAPABILITY_TTL_MS, CONTROL_PLANE_AUD } from "../src/auth/capability-token.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const execFileP = promisify(execFile);
const SECRET = "deploy-git-rw-secret".repeat(3);
@@ -34,6 +35,7 @@ function fixture(urls: { apiBaseUrl?: string; publicUrl?: string } = {}) {
const deployStore = createDeployStore({ git: { repoRoot: mkdtempSync(join(tmpdir(), "git-rw-repo-")) } });
const acl: AclStore = createAclStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/deploy-path-serving.test.ts b/test/deploy-path-serving.test.ts
index 31e016d10..318aac5b5 100644
--- a/test/deploy-path-serving.test.ts
+++ b/test/deploy-path-serving.test.ts
@@ -14,6 +14,7 @@ import { createDirectoryStore } from "../src/directory/directory-store.ts";
import { createIdentityService } from "../src/identity/identity-service.ts";
import { createMemorySessionStore } from "../src/sessions/memory-session-store.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const auditLog = { record() {}, events: async () => [], tail: async () => [] };
@@ -46,6 +47,7 @@ async function fixture(
const upstreamPort = (upstream.address() as AddressInfo).port;
const deployStore = createDeployStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/deploy-publish-gate-parity.test.ts b/test/deploy-publish-gate-parity.test.ts
index db68369d5..8f63f5dc3 100644
--- a/test/deploy-publish-gate-parity.test.ts
+++ b/test/deploy-publish-gate-parity.test.ts
@@ -10,6 +10,7 @@ import { createDirectoryStore, type DirectoryStore } from "../src/directory/dire
import { createIdentityService } from "../src/identity/identity-service.ts";
import { createCanReadScope, createCanWriteScope } from "../src/resolution/scope-membership.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const CH = "CBUILT";
const CH_OTHER = "CSHARED";
@@ -32,6 +33,7 @@ async function setup(opts: { withResolver: boolean } = { withResolver: true }) {
],
);
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/deploy-reap.test.ts b/test/deploy-reap.test.ts
index 97eb27e63..45ec096f0 100644
--- a/test/deploy-reap.test.ts
+++ b/test/deploy-reap.test.ts
@@ -8,6 +8,7 @@ import { createDeployService } from "../src/deploy/deploy-service.ts";
import { createAclStore } from "../src/acl/acl-store.ts";
import type { DeployProvider } from "../src/deploy/deploy-provider.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function svc(managedScaleToZero: boolean) {
const deployStore = createDeployStore();
@@ -20,6 +21,7 @@ function svc(managedScaleToZero: boolean) {
},
};
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider,
auditLog: { record() {}, events: async () => [], tail: async () => [] },
diff --git a/test/deploy-rename-display.test.ts b/test/deploy-rename-display.test.ts
index 6addbdfde..76ae2fa3f 100644
--- a/test/deploy-rename-display.test.ts
+++ b/test/deploy-rename-display.test.ts
@@ -11,11 +11,13 @@ import { createDeployService } from "../src/deploy/deploy-service.ts";
import { createAclStore } from "../src/acl/acl-store.ts";
import { scopeId } from "../src/types.ts";
import { mintSignedPayload } from "../src/auth/signed-token.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function svc() {
const deployStore = createDeployStore();
const acl = createAclStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/deploy-restore.test.ts b/test/deploy-restore.test.ts
index 4f4c3b52c..ec00a6c9e 100644
--- a/test/deploy-restore.test.ts
+++ b/test/deploy-restore.test.ts
@@ -7,11 +7,13 @@ import { createDeployService } from "../src/deploy/deploy-service.ts";
import { createDeployStore, type DeployStore } from "../src/deploy/deploy-store.ts";
import { createAclStore } from "../src/acl/acl-store.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function harness(failRestore = false) {
let applies = 0;
let destroys = 0;
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: {
profile: { managedScaleToZero: false },
@@ -50,6 +52,7 @@ function persistenceFailureHarness(failMethod: "setVersionImage" | "setEndpoint"
let destroys = 0;
let applies = 0;
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: store,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/deploy-store.test.ts b/test/deploy-store.test.ts
index 297ce38c9..476269267 100644
--- a/test/deploy-store.test.ts
+++ b/test/deploy-store.test.ts
@@ -17,6 +17,7 @@ import type { DeployGitArchive } from "../src/deploy/deploy-git-store.ts";
import { createMemoryDurableByteStore } from "../src/files/durable-byte-store.ts";
import { createMemoryMap } from "../src/persistence/durable-map.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
test("deploy versions are immutable and rollback flips the pointer", async () => {
const s = createDeployStore();
@@ -89,6 +90,7 @@ test("a provider without reconcile receives durable Git contents after a push",
const deployStore = createDeployStore({ git: { repoRoot: join(root, "repos") } });
const applied: string[] = [];
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
@@ -568,6 +570,7 @@ test("resident home files are held to the same path rules as app files", async (
const s = createDeployStore({ git: { repoRoot } });
const acl = createAclStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: s,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/deploy-subdomain-reach.test.ts b/test/deploy-subdomain-reach.test.ts
index 4fa0d7dde..3669e64e3 100644
--- a/test/deploy-subdomain-reach.test.ts
+++ b/test/deploy-subdomain-reach.test.ts
@@ -19,6 +19,7 @@ import { scopeId } from "../src/types.ts";
import { verifyPortalIdentity, PORTAL_IDENTITY_HEADER } from "../src/auth/portal-identity.ts";
import { viewerIdentityKey } from "../src/deploy/access-token.ts";
import type { AuditEvent } from "../src/audit/audit-log.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const audits: Array<(e: AuditEvent) => void> = [];
const onceKeys = new Set<string>();
@@ -52,6 +53,7 @@ function mintPortalSession(sub: string): string {
function serviceWithProvider(provider: DeployProvider) {
const deployStore = createDeployStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider,
auditLog,
@@ -140,6 +142,7 @@ test("reachDeployment: a provider without resolveEndpoint returns the frozen sto
function appServingUpstream(upstreamPort: number) {
const deployStore = createDeployStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/deploy-subdomain-signin.test.ts b/test/deploy-subdomain-signin.test.ts
index 193afd8e7..2c056c34c 100644
--- a/test/deploy-subdomain-signin.test.ts
+++ b/test/deploy-subdomain-signin.test.ts
@@ -18,6 +18,7 @@ import { PORTAL_IDENTITY_HEADER } from "../src/auth/portal-identity.ts";
import { portalSession } from "../src/deploy/viewer-session.ts";
import { scopeId } from "../src/types.ts";
import type { FeatureFlagStore } from "../src/feature-flags.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
let externalSharing = true;
const externalSharingOn = { enabled: async () => externalSharing } as unknown as FeatureFlagStore;
@@ -173,6 +174,7 @@ test("subdomain ingress: portal sign-in admits the owner, denies strangers, boun
const deployStore = createDeployStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
externalSharingAllowed: async () => true,
deployStore,
provider: {
@@ -374,6 +376,7 @@ test("org-wide app access admits only signed-in org members", async () => {
const acl = createAclStore();
const identity = createIdentityService();
const deploy = createDeployService({
+ ...singleProcessDeps(),
externalSharingAllowed: async () => false,
deployStore: createDeployStore(),
provider: {
@@ -434,6 +437,7 @@ test("org-wide app access admits only signed-in org members", async () => {
test("subdomain ingress: without the session config the domain has no door — a 503, not a bounce", async () => {
const deployStore = createDeployStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
externalSharingAllowed: async () => true,
deployStore,
provider: {
diff --git a/test/deployment-layer-store.test.ts b/test/deployment-layer-store.test.ts
index 0639b7235..a60011770 100644
--- a/test/deployment-layer-store.test.ts
+++ b/test/deployment-layer-store.test.ts
@@ -14,6 +14,7 @@ import { scopeId } from "../src/types.ts";
import type { AdvisoryLock } from "../src/persistence/advisory-lock.ts";
import { createAuditLog } from "../src/audit/audit-log.ts";
import { computeBundleHash, createSkillBundleStore } from "../src/skills/skill-bundle-store.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const tool = (advertise: string): DeploymentLayerBundle["tools"][number] => ({
path: "tools/acme/tool.json",
@@ -48,6 +49,7 @@ test("the durable deployment layer versions by content, hydrates runtime state,
const runtime = emptyDeploymentLayer();
let now = 100;
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime,
skills,
@@ -74,6 +76,7 @@ test("the durable deployment layer versions by content, hydrates runtime state,
const hydratedRuntime = emptyDeploymentLayer();
const hydrated = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: hydratedRuntime,
skills,
@@ -91,6 +94,7 @@ test("the durable deployment layer versions by content, hydrates runtime state,
test("invalid descriptors never replace the durable current layer", async () => {
const backing = createMemoryMap<StoredDeploymentLayer>();
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -133,6 +137,7 @@ test("a legacy published skill with an unsafe name is quarantined without blocki
});
const skills = createSkillStore({ signingSecret: "layer-test", backing: skillBacking });
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing: createMemoryMap<StoredDeploymentLayer>(),
runtime: emptyDeploymentLayer(),
skills,
@@ -152,7 +157,13 @@ test("a stale baked-in filesystem seed never downgrades or resurrects the durabl
const backing = createMemoryMap<StoredDeploymentLayer>();
const skills = createSkillStore({ signingSecret: "layer-test" });
const org = scopeId("org", "default-org");
- const writer = createDeploymentLayerStore({ backing, runtime: emptyDeploymentLayer(), skills, scopeId: org });
+ const writer = createDeploymentLayerStore({
+ ...singleProcessDeps(),
+ backing,
+ runtime: emptyDeploymentLayer(),
+ skills,
+ scopeId: org,
+ });
await writer.put(
{
contract: 1,
@@ -166,6 +177,7 @@ test("a stale baked-in filesystem seed never downgrades or resurrects the durabl
let seeded = 0;
const booted = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills,
@@ -193,6 +205,7 @@ test("with no durable record the filesystem seed applies once, and a later durab
const org = scopeId("org", "default-org");
let seeded = 0;
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills,
@@ -239,12 +252,14 @@ test("hydrate retries a transient backing read instead of failing boot", async (
const skills = createSkillStore({ signingSecret: "layer-test" });
const runtime = emptyDeploymentLayer();
await createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills,
scopeId: scopeId("org", "default-org"),
}).put({ contract: 1, tools: [tool("acme CLI")], skills: [] }, "api");
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing: flaky,
runtime,
skills,
@@ -275,6 +290,7 @@ test("a stored record that no longer applies degrades to the seed instead of fai
const runtime = resolvedDeploymentLayer("/fallback", []);
let seeded = 0;
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime,
skills,
@@ -298,6 +314,7 @@ test("a failed seed is retried on the next hydrate (seeded only latches on succe
const backing = createMemoryMap<StoredDeploymentLayer>();
let attempts = 0;
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -329,6 +346,7 @@ test("a failed fallback seed after an incompatible stored layer fails boot and r
});
let attempts = 0;
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: resolvedDeploymentLayer("/fallback", []),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -348,8 +366,15 @@ test("a PUT landing on another instance mid-seed is applied right after seeding
const backing = createMemoryMap<StoredDeploymentLayer>();
const skills = createSkillStore({ signingSecret: "layer-test" });
const org = scopeId("org", "default-org");
- const writer = createDeploymentLayerStore({ backing, runtime: emptyDeploymentLayer(), skills, scopeId: org });
+ const writer = createDeploymentLayerStore({
+ ...singleProcessDeps(),
+ backing,
+ runtime: emptyDeploymentLayer(),
+ skills,
+ scopeId: org,
+ });
const booted = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills,
@@ -390,6 +415,7 @@ test("a layer that appears mid-seed but fails to apply leaves the fallback live
const backing = createMemoryMap<StoredDeploymentLayer>();
const runtime = resolvedDeploymentLayer("/fallback", []);
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime,
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -429,6 +455,7 @@ test("a mid-seed layer that fails during skill mutation keeps the fallback live
};
const runtime = resolvedDeploymentLayer("/fallback", []);
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime,
skills,
@@ -464,6 +491,7 @@ test("a mid-seed layer that fails during skill mutation keeps the fallback live
test("misplaced tool files are rejected, not silently ignored", async () => {
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing: createMemoryMap<StoredDeploymentLayer>(),
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -481,6 +509,7 @@ test("misplaced tool files are rejected, not silently ignored", async () => {
test("live() reports the runtime source and durable reflects the backing", async () => {
const skills = createSkillStore({ signingSecret: "layer-test" });
const none = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing: createMemoryMap<StoredDeploymentLayer>(),
runtime: emptyDeploymentLayer(),
skills,
@@ -491,6 +520,7 @@ test("live() reports the runtime source and durable reflects the backing", async
const fsRuntime = resolvedDeploymentLayer("/layer", []);
const fs = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing: createMemoryMap<StoredDeploymentLayer>(),
runtime: fsRuntime,
skills,
@@ -508,6 +538,7 @@ test("live() reports the runtime source and durable reflects the backing", async
test("duplicate skill names across layer skill dirs are rejected at validation", async () => {
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing: createMemoryMap<StoredDeploymentLayer>(),
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -531,6 +562,7 @@ test("duplicate skill names across layer skill dirs are rejected at validation",
test("a NUL byte in the bundle is rejected at validation (Postgres JSONB would 500 on it later)", async () => {
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing: createMemoryMap<StoredDeploymentLayer>(),
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -551,6 +583,7 @@ test("a NUL byte in the bundle is rejected at validation (Postgres JSONB would 5
test("unpaired Unicode surrogates are rejected before the JSONB write", async () => {
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing: createMemoryMap<StoredDeploymentLayer>(),
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -572,6 +605,7 @@ test("unpaired Unicode surrogates are rejected before the JSONB write", async ()
test("PUT validates cross-tool credential paths before persisting", async () => {
const backing = createMemoryMap<StoredDeploymentLayer>();
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -628,6 +662,7 @@ test("hydrate reparses bundle descriptors instead of trusting stored resolved fi
});
const runtime = resolvedDeploymentLayer("/fallback", []);
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime,
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -644,6 +679,7 @@ test("hydrate derives runtime fields from the stored bundle, not the resolved ca
const backing = createMemoryMap<StoredDeploymentLayer>();
const bundle = { contract: 1 as const, tools: [tool("bundle truth")], skills: [] };
const writer = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -656,6 +692,7 @@ test("hydrate derives runtime fields from the stored bundle, not the resolved ca
});
const runtime = emptyDeploymentLayer();
const reader = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime,
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -673,6 +710,7 @@ test("a concurrent delete during put surfaces a conflict error, not a TypeError"
update: async () => null,
} as unknown as DurableMap<StoredDeploymentLayer>;
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -685,6 +723,7 @@ test("concurrent writes serialize into monotonic durable versions", async () =>
const backing = createMemoryMap<StoredDeploymentLayer>();
const runtime = emptyDeploymentLayer();
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime,
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -769,7 +808,14 @@ test("a failed multi-skill apply rolls every deployment-owned skill back before
};
const org = scopeId("org", "default-org");
const runtime = emptyDeploymentLayer();
- const store = createDeploymentLayerStore({ backing, runtime, skills, scopeId: org, retryDelaysMs: [] });
+ const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
+ backing,
+ runtime,
+ skills,
+ scopeId: org,
+ retryDelaysMs: [],
+ });
await store.put(
{
contract: 1,
@@ -813,7 +859,13 @@ test("applied status detects and repairs deployment-skill drift", async () => {
const backing = createMemoryMap<StoredDeploymentLayer>();
const skills = createSkillStore({ signingSecret: "layer-test" });
const org = scopeId("org", "default-org");
- const store = createDeploymentLayerStore({ backing, runtime: emptyDeploymentLayer(), skills, scopeId: org });
+ const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
+ backing,
+ runtime: emptyDeploymentLayer(),
+ skills,
+ scopeId: org,
+ });
const record = await store.put({ contract: 1, tools: [], skills: skill }, "api");
const deployed = (await skills.resolve("acme", [org])).skill!;
await skills.archive(deployed.id);
@@ -832,6 +884,7 @@ test("a later hydrate reconciles a persisted layer audit exactly once", async ()
const backing = createMemoryMap<StoredDeploymentLayer>();
const org = scopeId("org", "default-org");
const record = await createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -847,6 +900,7 @@ test("a later hydrate reconciles a persisted layer audit exactly once", async ()
scopeLabel: org,
});
const recovered = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -868,6 +922,7 @@ test("a failed audit remains recoverable after a later revision replaces the dur
const audited: number[] = [];
let auditAvailable = false;
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -901,7 +956,13 @@ test("a foreign same-name skill rejects the PUT before anything persists", async
manifest: { name: "acme", description: "user authored", requiredCapabilities: [], body: "mine" },
createdBy: "user:alice",
});
- const store = createDeploymentLayerStore({ backing, runtime: emptyDeploymentLayer(), skills, scopeId: org });
+ const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
+ backing,
+ runtime: emptyDeploymentLayer(),
+ skills,
+ scopeId: org,
+ });
await assert.rejects(
store.put({ contract: 1, tools: [], skills: skill }, "test"),
(e: unknown) => e instanceof DeploymentLayerValidationError && /created by user:alice/.test((e as Error).message),
@@ -912,6 +973,7 @@ test("a foreign same-name skill rejects the PUT before anything persists", async
test("deployment skill names cannot contain path separators", async () => {
const backing = createMemoryMap<StoredDeploymentLayer>();
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills: createSkillStore({ signingSecret: "layer-test" }),
@@ -949,6 +1011,7 @@ test("a deployment skill cannot materialize over an active pack's shared bundle"
const files = [{ path: "skills/acme/helpers/run.ts", content: "from pack" }];
await skillBundles.put({ packId: "one", commit: "abc", files, hash: computeBundleHash(files) });
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing,
runtime: emptyDeploymentLayer(),
skills,
@@ -993,7 +1056,7 @@ test("a foreign skill racing after validation reports the revision as persisted
},
};
const runtime = emptyDeploymentLayer();
- const store = createDeploymentLayerStore({ backing, runtime, skills, scopeId: org });
+ const store = createDeploymentLayerStore({ ...singleProcessDeps(), backing, runtime, skills, scopeId: org });
await assert.rejects(
store.put({ contract: 1, tools: [tool("acme CLI")], skills: skill }, "test"),
(error: unknown) =>
@@ -1019,7 +1082,7 @@ test("an archived foreign skill does not block the layer; a later live collision
await skills.archive(archived.id);
const runtime = emptyDeploymentLayer();
- const store = createDeploymentLayerStore({ backing, runtime, skills, scopeId: org });
+ const store = createDeploymentLayerStore({ ...singleProcessDeps(), backing, runtime, skills, scopeId: org });
const record = await store.put({ contract: 1, tools: [tool("acme CLI")], skills: skill }, "test");
assert.equal(
(await skills.resolve("acme", [org])).skill?.createdBy,
@@ -1038,7 +1101,13 @@ test("an archived foreign skill does not block the layer; a later live collision
await skills.review(mine.id, "user:alice", []);
await skills.publish(mine.id);
const fresh = emptyDeploymentLayer();
- const rehydrated = createDeploymentLayerStore({ backing, runtime: fresh, skills, scopeId: org });
+ const rehydrated = createDeploymentLayerStore({
+ ...singleProcessDeps(),
+ backing,
+ runtime: fresh,
+ skills,
+ scopeId: org,
+ });
assert.equal(
(await rehydrated.hydrate())?.contentHash,
record.contentHash,
@@ -1056,6 +1125,7 @@ test("an archived foreign skill does not block the layer; a later live collision
test("a bundle may carry the files a tool declares under install.files, and nothing else", async () => {
const runtime = emptyDeploymentLayer();
const store = createDeploymentLayerStore({
+ ...singleProcessDeps(),
backing: createMemoryMap<StoredDeploymentLayer>(),
runtime,
skills: createSkillStore({ signingSecret: "layer-test" }),
diff --git a/test/durable-process-sessions.test.ts b/test/durable-process-sessions.test.ts
index e52e7cf6d..f445e32d6 100644
--- a/test/durable-process-sessions.test.ts
+++ b/test/durable-process-sessions.test.ts
@@ -25,6 +25,7 @@ import { writableMemoryScope } from "../src/memory/policy.ts";
import type { Sandbox, ProcessSession, SandboxHandle } from "../src/sandbox/sandbox.ts";
import type { Conversation, Principal } from "../src/types.ts";
import { ProcessSessionGoneError } from "../src/sandbox/exec-process-session.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
const actor: Principal = { id: "U1", type: "internal" };
@@ -116,6 +117,7 @@ function buildOrchestrator(processes: ProcessRegistry, sandbox: Sandbox) {
const auditLog = createAuditLog();
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "dps-")));
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "dps-deploy"),
@@ -123,6 +125,7 @@ function buildOrchestrator(processes: ProcessRegistry, sandbox: Sandbox) {
acl,
});
return createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
resolution: createResolutionService(ORG, config, acl),
sessions: createMemorySessionStore(),
diff --git a/test/e2b-deploy-provider.test.ts b/test/e2b-deploy-provider.test.ts
index af2602390..bde1e57cd 100644
--- a/test/e2b-deploy-provider.test.ts
+++ b/test/e2b-deploy-provider.test.ts
@@ -11,6 +11,7 @@ import type { Deployment, DeploymentVersion } from "../src/deploy/deploy-store.t
import type { DeployProvider } from "../src/deploy/deploy-provider.ts";
import { scopeId } from "../src/types.ts";
import { installFakeE2b, type FakeE2b } from "./support/fake-e2b.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const SERVER = [
"const fs = require('fs');",
@@ -62,6 +63,7 @@ async function make(): Promise<{ provider: DeployProvider; store: DurableMap<Sto
fake = installFakeE2b({ info: true });
const store = createMemoryMap<StoredE2bDeployBody>();
const provider = createE2bDeployProvider({
+ ...singleProcessDeps(),
client: fake.client,
namePrefix: "qmt",
appPort,
diff --git a/test/e2b-sandbox.test.ts b/test/e2b-sandbox.test.ts
index 6e5a060a6..cd82b8ffb 100644
--- a/test/e2b-sandbox.test.ts
+++ b/test/e2b-sandbox.test.ts
@@ -18,6 +18,8 @@ import { installFakeE2b, type FakeE2b } from "./support/fake-e2b.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
import { E2bSandboxGoneError } from "../src/sandbox/e2b-client.ts";
import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
+import { createMemorySnapshotStore } from "../src/sandbox/home-snapshot.ts";
let fake: FakeE2b;
let sandbox: Sandbox;
@@ -27,6 +29,9 @@ const scopeName = (): string => sandboxScopeName("qmt", scope);
function make(extra: Record<string, unknown> = {}): Sandbox {
return createE2bSandbox(createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "e2b-ws-"))), {
+ snapshots: createMemorySnapshotStore(),
+ store: createMemoryMap(),
+ ...singleProcessDeps(),
client: fake.client,
namePrefix: "qmt",
...extra,
diff --git a/test/exec-kill.test.ts b/test/exec-kill.test.ts
index 5079dfb8c..ca0c3d17e 100644
--- a/test/exec-kill.test.ts
+++ b/test/exec-kill.test.ts
@@ -9,6 +9,8 @@ import { createLocalWorkspaceStore } from "../src/workspace/workspace-store.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
import { scopeId } from "../src/types.ts";
import { installFakeSprites, type FakeSprites } from "./support/fake-sprites.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
test("killableScript: records its PGID to the per-exec marker first, runs under setsid, preserves rc", () => {
const s = killableScript("do_work", "abc");
@@ -36,6 +38,8 @@ after(() => ff.cleanup());
function sprites(): Sandbox {
const dir = mkdtempSync(join(tmpdir(), "sprites-kill-ws-"));
return createSpritesSandbox(createLocalWorkspaceStore(dir), {
+ initializationStore: createMemoryMap(),
+ advisoryLock: createMemoryAdvisoryLock(),
token: "test-token",
baseUrl: ff.baseUrl,
});
diff --git a/test/execute-file-credentials.test.ts b/test/execute-file-credentials.test.ts
index 51f4a5d23..e2316243b 100644
--- a/test/execute-file-credentials.test.ts
+++ b/test/execute-file-credentials.test.ts
@@ -15,6 +15,7 @@ import { deriveConnectorKey } from "../src/connectors/connector-client-store.ts"
import { createToolContext, type ToolContextDeps } from "../src/tools/primitives.ts";
import type { ProcessSandbox, ProcessState, Sandbox, SandboxHandle } from "../src/sandbox/sandbox.ts";
import { scopeId } from "../src/types.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const run = promisify(execFile);
const SECRET_TOKEN = "synthetic-background-token-123";
@@ -28,6 +29,7 @@ async function fixture(t: TestContext) {
const root = await mkdtemp(join(tmpdir(), "qm-file-execution-test-"));
t.after(() => rm(root, { recursive: true, force: true }));
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/file-sharing.test.ts b/test/file-sharing.test.ts
index 7a89c4b90..1e59b3697 100644
--- a/test/file-sharing.test.ts
+++ b/test/file-sharing.test.ts
@@ -33,6 +33,8 @@ import {
turnFileId,
} from "../src/core/attachments.ts";
import { createAttachStaging } from "../src/core/orchestrator/attach-tool.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
test("turn file ids are stable within one attempt and fenced across retries", () => {
assert.equal(turnFileId("run-1", 1, 123), turnFileId("run-1", 1, 123));
@@ -538,7 +540,12 @@ test("removeDir wipes a per-turn spool dir (and only it), tolerating an absent d
const ff = installFakeSprites();
after(() => ff.cleanup());
const ws = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "fs-rm-")));
- const sandbox = createSpritesSandbox(ws, { token: "test-token", baseUrl: ff.baseUrl });
+ const sandbox = createSpritesSandbox(ws, {
+ initializationStore: createMemoryMap(),
+ advisoryLock: createMemoryAdvisoryLock(),
+ token: "test-token",
+ baseUrl: ff.baseUrl,
+ });
const handle = await sandbox.provision([{ scopeId: "personal:U1", mountPath: "", mode: "rw" }]);
await sandbox.writeFileBytes(handle, "spool/one.txt", new Uint8Array(Buffer.from("1")));
await sandbox.writeFileBytes(handle, "spool/two.txt", new Uint8Array(Buffer.from("2")));
@@ -558,7 +565,12 @@ test("a binary file round-trips through the sandbox (base64-over-exec) without u
const ff = installFakeSprites();
after(() => ff.cleanup());
const ws = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "fs-bin-")));
- const sandbox = createSpritesSandbox(ws, { token: "test-token", baseUrl: ff.baseUrl });
+ const sandbox = createSpritesSandbox(ws, {
+ initializationStore: createMemoryMap(),
+ advisoryLock: createMemoryAdvisoryLock(),
+ token: "test-token",
+ baseUrl: ff.baseUrl,
+ });
const handle = await sandbox.provision([{ scopeId: "personal:U1", mountPath: "", mode: "rw" }]);
const raw = new Uint8Array([0x00, 0x9f, 0x92, 0x96, 0xff, 0xfe]);
await sandbox.writeFileBytes(handle, "keep.bin", raw);
diff --git a/test/finalize-on-reply-ready.test.ts b/test/finalize-on-reply-ready.test.ts
index 1fbac1cb4..19c1b5a66 100644
--- a/test/finalize-on-reply-ready.test.ts
+++ b/test/finalize-on-reply-ready.test.ts
@@ -24,6 +24,7 @@ import type { Sandbox, SandboxHandle, TeardownOptions } from "../src/sandbox/san
import type { ErrorLog } from "../src/admin/error-log.ts";
import type { SurfaceCache } from "../src/surface-cache/types.ts";
import type { Conversation, Principal } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
const actor: Principal = { id: "U1", type: "internal" };
@@ -111,6 +112,7 @@ function buildOrchestrator(
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "frr-")));
const sessions = createMemorySessionStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "frr-deploy"),
@@ -118,6 +120,7 @@ function buildOrchestrator(
acl,
});
const orch = createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
resolution: createResolutionService(ORG, config, acl),
sessions,
diff --git a/test/keychain-approval-card.test.ts b/test/keychain-approval-card.test.ts
index 7b551391d..2cc3a3c66 100644
--- a/test/keychain-approval-card.test.ts
+++ b/test/keychain-approval-card.test.ts
@@ -15,6 +15,7 @@ import {
import type { App } from "../src/api/app.ts";
import type { Directory } from "../src/slack/directory.ts";
import type { SlackCoreClient } from "../src/api/slack-core-client.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
async function fixture() {
let now = Date.now();
@@ -22,6 +23,7 @@ async function fixture() {
const grants = createMemoryMap<KeychainGrant>();
const asks = createMemoryMap<KeychainAsk>();
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants,
asks,
diff --git a/test/keychain-ask.test.ts b/test/keychain-ask.test.ts
index 1e3a4500b..ec827aef2 100644
--- a/test/keychain-ask.test.ts
+++ b/test/keychain-ask.test.ts
@@ -36,12 +36,15 @@ import { fakeSprites } from "./support/auto-fake-sprites.ts";
import { testConfig } from "./support/test-config.ts";
import { selectDefaultSandbox } from "./support/default-sandbox.ts";
import { materializeGrant } from "./support/materialize-grant.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const KEY = deriveConnectorKey("keychain-ask-test-key");
const SECRET = "keychain-ask-route-secret".repeat(3);
function kcAt(now: () => number): Keychain {
return createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
@@ -303,6 +306,7 @@ test("expiry sweep fires the resolution once and rides the scheduler tick", asyn
const swept: number[] = [];
const idStore = createIdempotencyStore(createMemoryMap<IdempotencyRecord>());
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons: createCronStore(createMemoryMap()),
deliveries: createDeliveryStore(),
idempotency: idStore,
diff --git a/test/keychain.test.ts b/test/keychain.test.ts
index 289ebc98a..e3579ef0f 100644
--- a/test/keychain.test.ts
+++ b/test/keychain.test.ts
@@ -27,11 +27,13 @@ import { fakeSprites } from "./support/auto-fake-sprites.ts";
import { testConfig } from "./support/test-config.ts";
import { selectDefaultSandbox } from "./support/default-sandbox.ts";
import { materializeGrant } from "./support/materialize-grant.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const KEY = deriveConnectorKey("keychain-test-key");
function kc(now?: () => number): Keychain {
return createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
@@ -98,7 +100,13 @@ test("listing and per-owner reads use the store's projected select and never a f
return backing.select(query);
},
};
- const k = createKeychain({ creds, grants: createMemoryMap(), asks: createMemoryMap(), key: KEY });
+ const k = createKeychain({
+ lock: createMemoryAdvisoryLock(),
+ creds,
+ grants: createMemoryMap(),
+ asks: createMemoryMap(),
+ key: KEY,
+ });
const org = scopeId("org", "default-org");
await k.save({ ...GH, ownerId: "[email protected]" });
await k.save(GH);
@@ -214,7 +222,13 @@ test("concurrent materialization consumes a once grant exactly once", async () =
test("legacy retry grants remain consumed and invalidate prepared uses", async () => {
const grants = createMemoryMap<KeychainGrant>();
- const k = createKeychain({ creds: createMemoryMap(), grants, asks: createMemoryMap(), key: KEY });
+ const k = createKeychain({
+ lock: createMemoryAdvisoryLock(),
+ creds: createMemoryMap(),
+ grants,
+ asks: createMemoryMap(),
+ key: KEY,
+ });
const credential = await k.save(GH);
const grant = await k.createGrant({
credentialId: credential.id,
@@ -276,7 +290,7 @@ test("materializeOwnById: the owner's own credential needs no grant — scope, o
test("a grant row pointing at a broker credential cannot materialize (defense in depth)", async () => {
const creds = createMemoryMap<import("../src/credentials/keychain.ts").KeychainCredential>();
const grants = createMemoryMap<import("../src/credentials/keychain.ts").KeychainGrant>();
- const k = createKeychain({ creds, grants, asks: createMemoryMap(), key: KEY });
+ const k = createKeychain({ lock: createMemoryAdvisoryLock(), creds, grants, asks: createMemoryMap(), key: KEY });
const ORG = scopeId("org", "default-org");
await k.setServiceCredential(ORG, { slug: "serp", name: "SERP", secret: "s3", host: "api.serper.dev" });
const broker = (await creds.all()).find((c) => c.kind === "broker")!;
@@ -307,6 +321,7 @@ describe("connectors are grantable like any keychain record", () => {
type Rec = import("../src/credentials/keychain.ts").KeychainCredential;
function kcWithRefresh(freshToken: string): Keychain {
return createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap<Rec>(),
grants: createMemoryMap(),
asks: createMemoryMap(),
@@ -671,10 +686,22 @@ test("materializeOwn round-trips the owner's env creds; expired creds are skippe
test("materializeOwn skips a row that doesn't decrypt under the current key instead of throwing", async () => {
const creds = createMemoryMap<import("../src/credentials/keychain.ts").KeychainCredential>();
const OTHER = deriveConnectorKey("a-different-master-key");
- const writer = createKeychain({ creds, grants: createMemoryMap(), asks: createMemoryMap(), key: OTHER });
+ const writer = createKeychain({
+ lock: createMemoryAdvisoryLock(),
+ creds,
+ grants: createMemoryMap(),
+ asks: createMemoryMap(),
+ key: OTHER,
+ });
await writer.save({ ownerId: "U1", service: "stripe", secret: "sk_bad", envKey: "STRIPE_KEY" });
- const reader = createKeychain({ creds, grants: createMemoryMap(), asks: createMemoryMap(), key: KEY });
+ const reader = createKeychain({
+ lock: createMemoryAdvisoryLock(),
+ creds,
+ grants: createMemoryMap(),
+ asks: createMemoryMap(),
+ key: KEY,
+ });
await reader.save(GH);
const own = await reader.materializeOwn("U1");
@@ -689,10 +716,16 @@ test("single-grant materialize surfaces a 422 (not a raw crypto 500) when the ro
const creds = createMemoryMap<import("../src/credentials/keychain.ts").KeychainCredential>();
const grants = createMemoryMap<import("../src/credentials/keychain.ts").KeychainGrant>();
const OTHER = deriveConnectorKey("a-different-master-key");
- const writer = createKeychain({ creds, grants, asks: createMemoryMap(), key: OTHER });
+ const writer = createKeychain({
+ lock: createMemoryAdvisoryLock(),
+ creds,
+ grants,
+ asks: createMemoryMap(),
+ key: OTHER,
+ });
const cred = await writer.save({ ownerId: "U1", service: "stripe", secret: "sk_bad", envKey: "STRIPE_KEY" });
- const reader = createKeychain({ creds, grants, asks: createMemoryMap(), key: KEY });
+ const reader = createKeychain({ lock: createMemoryAdvisoryLock(), creds, grants, asks: createMemoryMap(), key: KEY });
const grant = await reader.createGrant({
credentialId: cred.id,
ownerId: "U1",
@@ -792,7 +825,13 @@ test("multi-input login: re-save upserts the same slot, and unique/non-empty fie
test("back-compat: a legacy record carrying a plaintext username still materializes the paired env var", async () => {
const creds = createMemoryMap<import("../src/credentials/keychain.ts").KeychainCredential>();
- const k = createKeychain({ creds, grants: createMemoryMap(), asks: createMemoryMap(), key: KEY });
+ const k = createKeychain({
+ lock: createMemoryAdvisoryLock(),
+ creds,
+ grants: createMemoryMap(),
+ asks: createMemoryMap(),
+ key: KEY,
+ });
const meta = await k.save({
ownerId: "U1",
service: "acme-portal",
@@ -1342,6 +1381,7 @@ test("prepared grants reject credential rotation without consuming a single use"
test("connector refresh during preparation binds the refreshed version and later rotation invalidates it", async () => {
let refreshes = 0;
const k = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
@@ -1408,6 +1448,7 @@ test("Composio keys remain backend-only across all materialization paths includi
test("manifest timestamps stay stable until credentials and pending asks actually expire", async () => {
let now = Date.parse("2030-01-01T00:00:00Z");
const k = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/loop-cron-delegation.test.ts b/test/loop-cron-delegation.test.ts
index b8acd8a22..afdd10f96 100644
--- a/test/loop-cron-delegation.test.ts
+++ b/test/loop-cron-delegation.test.ts
@@ -4,6 +4,7 @@ import { createScheduler } from "../src/cron/scheduler.ts";
import { createCronStore } from "../src/cron/cron-store.ts";
import { createIdempotencyStore } from "../src/idempotency/idempotency-store.ts";
import { scopeId, type TurnRequest, type TurnResult } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const base = { owner: "josh", createdBy: "josh", ownerScopeId: scopeId("personal", "josh") };
@@ -12,6 +13,7 @@ function deps(fired: string[], turns: TurnRequest[]) {
return {
crons,
scheduler: createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: { enqueue: async () => ({ id: "d" }) } as never,
idempotency: createIdempotencyStore(),
@@ -57,6 +59,7 @@ test("a failing loop fire is recorded on the cron's fire log and the schedule ad
const turns: TurnRequest[] = [];
const crons = createCronStore();
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: { enqueue: async () => ({ id: "d" }) } as never,
idempotency: createIdempotencyStore(),
@@ -83,6 +86,7 @@ test("a loop-backed cron fails closed when the loop service is unavailable", asy
const turns: TurnRequest[] = [];
const crons = createCronStore();
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: { enqueue: async () => ({ id: "d" }) } as never,
idempotency: createIdempotencyStore(),
diff --git a/test/loop-fire.test.ts b/test/loop-fire.test.ts
index 0256c91d9..d7c076b7c 100644
--- a/test/loop-fire.test.ts
+++ b/test/loop-fire.test.ts
@@ -14,6 +14,7 @@ import { buildShipGrant } from "../src/loops/ship-gate.ts";
import { createIdempotencyStore } from "../src/idempotency/idempotency-store.ts";
import { createDirectoryStore } from "../src/directory/directory-store.ts";
import { scopeId, type TurnRequest, type TurnResult } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function fakeIdentity() {
return {
@@ -623,6 +624,7 @@ for (const unattendedGrants of [undefined, ["admin.sessions.read"]]) {
const loop = await makeLoop(s.loops);
const cron = await bindCron(s, loop, { unattendedGrants, destination: { type: "slack", target: "C-alerts" } });
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons: s.crons,
deliveries: s.deliveries.store as never,
idempotency: s.idempotency,
diff --git a/test/managed-agents-sandbox.test.ts b/test/managed-agents-sandbox.test.ts
index 832548b3d..62123a8d6 100644
--- a/test/managed-agents-sandbox.test.ts
+++ b/test/managed-agents-sandbox.test.ts
@@ -23,6 +23,7 @@ import { scopeId } from "../src/types.ts";
import { prepareExecutionFiles } from "../src/credentials/execute-files.ts";
import { installFakeManagedAgents, type FakeManagedAgents } from "./support/fake-managed-agents.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
+import { createMemorySnapshotStore } from "../src/sandbox/home-snapshot.ts";
let fake: FakeManagedAgents;
let sandbox: Sandbox;
@@ -32,6 +33,8 @@ const scopeName = (): string => sandboxScopeName("qmt", scope);
function make(extra: Record<string, unknown> = {}): Sandbox {
return createManagedAgentsSandbox(createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "managed-agents-ws-"))), {
+ snapshots: createMemorySnapshotStore(),
+ store: createMemoryMap(),
client: fake.client,
namePrefix: "qmt",
...extra,
diff --git a/test/mcp-connectors.test.ts b/test/mcp-connectors.test.ts
index 82f671ee9..86f11b865 100644
--- a/test/mcp-connectors.test.ts
+++ b/test/mcp-connectors.test.ts
@@ -11,6 +11,7 @@ import type { AddressInfo } from "node:net";
import { createMemoryMap } from "../src/persistence/durable-map.ts";
import { settle } from "./support/settle.ts";
import { startMcpTestServer } from "./support/mcp-test-server.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
function server(partial?: Partial<McpServer>): McpServer {
return {
@@ -175,6 +176,7 @@ test("unknown tool call rejects", async () => {
function tokenStore() {
return createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap<KeychainCredential>(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/memory-capture-async.test.ts b/test/memory-capture-async.test.ts
index ee8a32984..b976417d8 100644
--- a/test/memory-capture-async.test.ts
+++ b/test/memory-capture-async.test.ts
@@ -26,6 +26,7 @@ import { createMemoryDurableByteStore } from "../src/files/durable-byte-store.ts
import type { Harness } from "../src/harness/harness.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
import type { Conversation, Principal } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
const actor: Principal = { id: "U1", type: "internal" };
@@ -95,6 +96,7 @@ function buildOrchestrator(harness: Harness, memory?: MemoryService, memoryStrat
const auditLog = createAuditLog();
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "mca-")));
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "mca-deploy"),
@@ -102,6 +104,7 @@ function buildOrchestrator(harness: Harness, memory?: MemoryService, memoryStrat
acl,
});
return createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
resolution: createResolutionService(ORG, config, acl),
sessions: createMemorySessionStore(),
diff --git a/test/memory-tidy.test.ts b/test/memory-tidy.test.ts
index 8b35e68c3..7436a1444 100644
--- a/test/memory-tidy.test.ts
+++ b/test/memory-tidy.test.ts
@@ -10,6 +10,7 @@ import { createIdempotencyStore } from "../src/idempotency/idempotency-store.ts"
import { createIdentityService } from "../src/identity/identity-service.ts";
import type { MemoryFact } from "../src/memory/facts.ts";
import { scopeId, type ScopeId, type TurnRequest } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function fixture() {
const notebooks = new Map<ScopeId, MemoryFact[]>();
@@ -35,6 +36,7 @@ function fixture() {
};
const service = createMemoryTidyService(deps);
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries: createDeliveryStore(),
identity: createIdentityService(),
diff --git a/test/modal-sandbox.test.ts b/test/modal-sandbox.test.ts
index dac4580be..5b5f4c534 100644
--- a/test/modal-sandbox.test.ts
+++ b/test/modal-sandbox.test.ts
@@ -18,6 +18,8 @@ import { mintCapabilityToken, EGRESS_PROXY_AUD } from "../src/auth/capability-to
import { installFakeModal, type FakeModal } from "./support/fake-modal.ts";
import { ModalSandboxGoneError, type ModalClient } from "../src/sandbox/modal-client.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
+import { createMemorySnapshotStore } from "../src/sandbox/home-snapshot.ts";
let fake: FakeModal;
let sandbox: Sandbox;
@@ -27,6 +29,9 @@ const scopeName = (): string => sandboxScopeName("qmt", scope);
function make(extra: Record<string, unknown> = {}): Sandbox {
return createModalSandbox(createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "modal-ws-"))), {
+ snapshots: createMemorySnapshotStore(),
+ store: createMemoryMap(),
+ ...singleProcessDeps(),
client: fake.client,
namePrefix: "qmt",
nativeSnapshotsEnabled: true,
@@ -156,6 +161,9 @@ test("a create race with another core instance adopts the winner instead of erro
};
await make().provision(layers);
const s = createModalSandbox(createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "modal-ws-"))), {
+ snapshots: createMemorySnapshotStore(),
+ store: createMemoryMap(),
+ ...singleProcessDeps(),
client: racing,
namePrefix: "qmt",
});
@@ -245,6 +253,25 @@ test("a sandbox older than rotateAfterMs is rotated at provision with files inta
assert.equal(fake.runningCount(), 1, "the stale box was terminated, not leaked");
});
+test("an aged sandbox rotates only when its home can be carried over", async () => {
+ for (const [snapshots, rotates] of [
+ [undefined, false],
+ [createMemorySnapshotStore(), true],
+ ] as const) {
+ const store = createMemoryMap<StoredModalSandbox>();
+ const s = make({ store, snapshots, nativeSnapshotsEnabled: false });
+ const a = await s.provision(layers);
+ await s.writeFile(a, "keep.txt", "home\n");
+ await s.teardown(a);
+ await store.merge(scope, { createdAtMs: Date.now() - 21 * 3600_000 });
+ const before = fake.createdCount(scopeName());
+ const b = await s.provision(layers);
+ assert.equal(fake.createdCount(scopeName()) - before, rotates ? 1 : 0);
+ assert.equal(await s.readFile(b, "keep.txt"), "home\n");
+ await s.teardown(b, { destroy: true });
+ }
+});
+
test("rotation snapshots changes written since the last teardown snapshot", async () => {
const store = createMemoryMap<StoredModalSandbox>();
const s = make({ store });
diff --git a/test/monitor-poller.test.ts b/test/monitor-poller.test.ts
index b9f8274da..38ac3ab8d 100644
--- a/test/monitor-poller.test.ts
+++ b/test/monitor-poller.test.ts
@@ -10,6 +10,7 @@ import type { LeaderLease } from "../src/persistence/leader-lease.ts";
import { scopeId, type TurnRequest, type TurnResult } from "../src/types.ts";
import type { ProcessSandbox, ProcessSession, SandboxHandle } from "../src/sandbox/sandbox.ts";
import { ProcessSessionGoneError } from "../src/sandbox/exec-process-session.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const SCOPE = "personal:U1";
const handle: SandboxHandle = { id: "vm", rootDir: "/workspace", homeDir: "/root" };
@@ -113,6 +114,7 @@ async function harness(opts?: {
};
const identity = createIdentityService();
const poller = createMonitorPoller({
+ ...singleProcessDeps(),
monitors,
processes,
sandbox: fake.sandbox,
diff --git a/test/native-provider-clients.test.ts b/test/native-provider-clients.test.ts
index 5f1bbab2a..ff64f4906 100644
--- a/test/native-provider-clients.test.ts
+++ b/test/native-provider-clients.test.ts
@@ -22,6 +22,9 @@ import {
E2bCommandLostError,
E2bSandboxGoneError,
} from "../src/sandbox/e2b-client.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
+import { createMemorySnapshotStore } from "../src/sandbox/home-snapshot.ts";
const modalCalls: unknown[][] = [];
const modalCreateParams: Record<string, unknown>[] = [];
@@ -505,7 +508,12 @@ test("E2B does not dispatch twice when execution occurs before its start acknowl
onDispatch = undefined;
rmSync(root, { recursive: true, force: true });
});
- const sandbox = createE2bSandbox(createLocalWorkspaceStore(root), { client: createSdkE2bClient({ apiKey: "test" }) });
+ const sandbox = createE2bSandbox(createLocalWorkspaceStore(root), {
+ snapshots: createMemorySnapshotStore(),
+ store: createMemoryMap(),
+ ...singleProcessDeps(),
+ client: createSdkE2bClient({ apiKey: "test" }),
+ });
const handle = await sandbox.provision([{ scopeId: "lost-start", mountPath: "", mode: "rw" }]);
let effects = 0;
onDispatch = (command) => {
@@ -554,6 +562,9 @@ test("Modal executes a one-megabyte payload through the sandbox and SDK without
const client = createSdkModalClient({ tokenId: "id", tokenSecret: "secret", appName: "test", image: "ubuntu" });
const session = await client.create({});
const sandbox = createModalSandbox(createLocalWorkspaceStore(join(root, "workspace")), {
+ snapshots: createMemorySnapshotStore(),
+ store: createMemoryMap(),
+ ...singleProcessDeps(),
client: {
create: async () => session,
fromId: async () => session,
diff --git a/test/porter-deploy-provider.test.ts b/test/porter-deploy-provider.test.ts
index 45d614ead..6a88a9884 100644
--- a/test/porter-deploy-provider.test.ts
+++ b/test/porter-deploy-provider.test.ts
@@ -12,6 +12,7 @@ import type { DeployProvider } from "../src/deploy/deploy-provider.ts";
import { NotFoundError } from "porter-sandbox";
import { scopeId } from "../src/types.ts";
import { installFakePorter, type FakePorter } from "./support/fake-porter.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const SERVER = [
"const fs = require('fs');",
@@ -81,6 +82,7 @@ function make(
fake = installFakePorter(extra.terminateLag ? { terminateLag: extra.terminateLag } : {});
store = createMemoryMap<StoredPorterDeployBody>();
provider = createPorterDeployProvider({
+ ...singleProcessDeps(),
appsDomain: "apps.test",
namePrefix: "qmt",
appPort,
@@ -172,6 +174,7 @@ test("explicit public visibility opts the domain out of the private default", as
test("without an apps domain the app defaults to its cluster-internal address", async () => {
const bare = createPorterDeployProvider({
+ ...singleProcessDeps(),
namePrefix: "qmt",
appPort,
readyWindowSec: 10,
@@ -400,6 +403,7 @@ test("a body that vanished between list and terminate does not break destroy or
test("without an apps domain a private app gets the host the cluster names", async () => {
const bare = createPorterDeployProvider({
+ ...singleProcessDeps(),
visibility: "private",
namePrefix: "qmt",
appPort,
@@ -419,6 +423,7 @@ test("a cluster that names no host fails the deploy and leaves no body behind",
fake.cleanup();
fake = installFakePorter({ assignHost: false });
const bare = createPorterDeployProvider({
+ ...singleProcessDeps(),
visibility: "private",
namePrefix: "qmt",
appPort,
diff --git a/test/porter-sandbox.test.ts b/test/porter-sandbox.test.ts
index 510527921..5a542021d 100644
--- a/test/porter-sandbox.test.ts
+++ b/test/porter-sandbox.test.ts
@@ -12,6 +12,7 @@ import { supportsProcessSessions } from "../src/sandbox/sandbox.ts";
import { scopeId } from "../src/types.ts";
import { installFakePorter, type FakePorter } from "./support/fake-porter.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
let fake: FakePorter;
let sandbox: Sandbox;
@@ -21,6 +22,7 @@ const slug = porterScopeSlug("qmt", scope);
function make(extra: Record<string, unknown> = {}): Sandbox {
return createPorterSandbox(createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "porter-ws-"))), {
+ ...singleProcessDeps(),
namePrefix: "qmt",
client: fake.client,
...extra,
diff --git a/test/postgres-map.test.ts b/test/postgres-map.test.ts
index 3d8d337bc..90ed5fc8e 100644
--- a/test/postgres-map.test.ts
+++ b/test/postgres-map.test.ts
@@ -15,6 +15,7 @@ import {
import { deriveConnectorKey } from "../src/connectors/connector-client-store.ts";
import { applyPgMigrations, definePgMigration } from "../src/persistence/pg-pool.ts";
import { materializeGrant } from "./support/materialize-grant.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const URL = process.env.DATABASE_URL;
const skip = URL ? false : "set DATABASE_URL (a Postgres) to run the Postgres map tests";
@@ -323,6 +324,7 @@ test("pg map: original folded-index migration upgrades without changing its ledg
test("pg keychain: listByOwner is a per-owner projected read with no secret material", { skip }, async () => {
const factory = createPostgresMapFactory(URL!);
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: factory.map<KeychainCredential>("map_keychain_creds", ["ownerId"]),
grants: factory.map<KeychainGrant>("map_keychain_grants", ["ownerId"]),
asks: factory.map<KeychainAsk>("map_keychain_asks"),
@@ -360,6 +362,7 @@ test("pg map: concurrent keychain instances claim a once grant exactly once", {
const key = deriveConnectorKey("postgres-keychain-test-key");
const build = (factory: ReturnType<typeof createPostgresMapFactory>) =>
createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: factory.map<KeychainCredential>("map_keychain_creds", ["ownerId"]),
grants: factory.map<KeychainGrant>("map_keychain_grants", ["ownerId"]),
asks: factory.map<KeychainAsk>("map_keychain_asks"),
diff --git a/test/principal-links.test.ts b/test/principal-links.test.ts
index e7c7e28ab..ebb4acf1a 100644
--- a/test/principal-links.test.ts
+++ b/test/principal-links.test.ts
@@ -30,6 +30,7 @@ import { mintSignedPayload } from "../src/auth/signed-token.ts";
import { signedRequestHeaders } from "../plugins/chassis/src/source-auth-sign.ts";
import { scopeId } from "../src/types.ts";
import { testConfig } from "./support/test-config.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const EMAIL = "[email protected]";
const SLACK = "U0JORDAN";
@@ -194,6 +195,7 @@ describe("person primitives fold a linked sign-in to its canonical principal", (
await installed();
const creds = createMemoryMap<KeychainCredential>();
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds,
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/process-reaper.test.ts b/test/process-reaper.test.ts
index 29d645f24..4b8c3b8cf 100644
--- a/test/process-reaper.test.ts
+++ b/test/process-reaper.test.ts
@@ -6,6 +6,7 @@ import type { LeaderLease } from "../src/persistence/leader-lease.ts";
import type { ProcessSandbox, SandboxHandle, ProvisionOptions, TeardownOptions } from "../src/sandbox/sandbox.ts";
import type { WorkspaceLayer } from "../src/types.ts";
import { ProcessSessionGoneError } from "../src/sandbox/exec-process-session.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
@@ -59,6 +60,7 @@ test("reaper flips expired sessions and calls kill for each", async () => {
});
const killed: string[] = [];
const reaper = createProcessReaper(reg, {
+ ...singleProcessDeps(),
intervalMs: 60_000,
kill: async (r: ProcessRecord) => void killed.push(r.processId),
});
@@ -82,6 +84,7 @@ test("reaper calls onReaped for each reaped record (so a reaped run's death can
});
const seen: Array<{ kind: string; runId?: string }> = [];
const reaper = createProcessReaper(reg, {
+ ...singleProcessDeps(),
intervalMs: 60_000,
onReaped: async (r: ProcessRecord) => void seen.push({ kind: r.kind, ...(r.runId ? { runId: r.runId } : {}) }),
});
@@ -107,6 +110,7 @@ test("a row deleted mid-sweep (a run that finished between snapshot and mark) is
});
const notified: string[] = [];
const reaper = createProcessReaper(reg, {
+ ...singleProcessDeps(),
intervalMs: 60_000,
kill: async (r: ProcessRecord) => {
await reg.delete(r.processId);
@@ -129,6 +133,7 @@ test("an onReaped failure does not abort the sweep or un-reap the record", async
runId: "run-7",
});
const reaper = createProcessReaper(reg, {
+ ...singleProcessDeps(),
intervalMs: 60_000,
onReaped: async () => {
throw new Error("delivery store down");
@@ -148,7 +153,7 @@ test("reaper leaves unexpired sessions alone", async () => {
command: "make",
ttlMs: 60_000,
});
- const reaper = createProcessReaper(reg, { intervalMs: 60_000 });
+ const reaper = createProcessReaper(reg, { ...singleProcessDeps(), intervalMs: 60_000 });
assert.equal((await reaper.sweep()).reaped, 0);
assert.equal((await reg.liveByScope("s")).length, 1);
});
@@ -173,6 +178,7 @@ test("a kill failure does not abort the sweep, leaves the record running, and is
});
let failFirst = true;
const reaper = createProcessReaper(reg, {
+ ...singleProcessDeps(),
intervalMs: 60_000,
kill: async (r: ProcessRecord) => {
if (failFirst && r.processId === bgId(1)) throw new Error("boom");
@@ -216,7 +222,11 @@ test("kill hook SIGTERMs every expired kind — background, build, and dev-serve
});
const { sandbox, provisions, signals, teardowns } = killSpySandbox();
- const reaper = createProcessReaper(reg, { intervalMs: 60_000, kill: createReaperKillHook(sandbox, FAST_GRACE) });
+ const reaper = createProcessReaper(reg, {
+ ...singleProcessDeps(),
+ intervalMs: 60_000,
+ kill: createReaperKillHook(sandbox, FAST_GRACE),
+ });
const { reaped } = await reaper.sweep();
assert.equal(reaped, 3, "all three rows are reaped (status flipped)");
@@ -247,7 +257,11 @@ test("kill hook escalates TERM → KILL when the grace period passes without an
ttlMs: -1,
});
const { sandbox, signals } = killSpySandbox({ diesOn: "KILL" });
- const reaper = createProcessReaper(reg, { intervalMs: 60_000, kill: createReaperKillHook(sandbox, FAST_GRACE) });
+ const reaper = createProcessReaper(reg, {
+ ...singleProcessDeps(),
+ intervalMs: 60_000,
+ kill: createReaperKillHook(sandbox, FAST_GRACE),
+ });
assert.equal((await reaper.sweep()).reaped, 1);
assert.deepEqual(
@@ -268,7 +282,11 @@ test("a process that survives TERM+KILL is NOT marked reaped (zombie stays visib
ttlMs: -1,
});
const { sandbox, signals } = killSpySandbox({ diesOn: "never" });
- const reaper = createProcessReaper(reg, { intervalMs: 60_000, kill: createReaperKillHook(sandbox, FAST_GRACE) });
+ const reaper = createProcessReaper(reg, {
+ ...singleProcessDeps(),
+ intervalMs: 60_000,
+ kill: createReaperKillHook(sandbox, FAST_GRACE),
+ });
assert.equal((await reaper.sweep()).reaped, 0);
assert.deepEqual(
@@ -330,7 +348,11 @@ test("a vanished process session counts as a confirmed kill", async () => {
ttlMs: -1,
});
const { sandbox, teardowns } = killSpySandbox({ vanished: true });
- const reaper = createProcessReaper(reg, { intervalMs: 60_000, kill: createReaperKillHook(sandbox, FAST_GRACE) });
+ const reaper = createProcessReaper(reg, {
+ ...singleProcessDeps(),
+ intervalMs: 60_000,
+ kill: createReaperKillHook(sandbox, FAST_GRACE),
+ });
assert.equal((await reaper.sweep()).reaped, 1);
assert.equal((await reg.get(ID))!.status, "reaped");
@@ -347,7 +369,11 @@ test("an expired job with no recorded computer is retired without touching the s
ttlMs: -1,
} as unknown as Parameters<typeof reg.register>[0]);
const { sandbox, provisions, signals } = killSpySandbox();
- const reaper = createProcessReaper(reg, { intervalMs: 60_000, kill: createReaperKillHook(sandbox, FAST_GRACE) });
+ const reaper = createProcessReaper(reg, {
+ ...singleProcessDeps(),
+ intervalMs: 60_000,
+ kill: createReaperKillHook(sandbox, FAST_GRACE),
+ });
assert.equal((await reaper.sweep()).reaped, 1);
assert.equal(provisions.length, 0);
assert.equal(signals.length, 0);
diff --git a/test/projects.test.ts b/test/projects.test.ts
index b333c0454..7c54863fc 100644
--- a/test/projects.test.ts
+++ b/test/projects.test.ts
@@ -23,10 +23,12 @@ import {
import { buildApp } from "../src/wiring.ts";
import { testConfig } from "./support/test-config.ts";
import { runNowSettled } from "./support/settle.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
test("ProjectStore atomically maintains a managed-group roster", async () => {
let at = 10;
- const projects = createProjectStore(undefined, { id: () => "p1", now: () => at++ });
+ const projects = createProjectStore(createMemoryMap(), { ...singleProcessDeps(), id: () => "p1", now: () => at++ });
const project = await projects.create({ name: " Launch Cohort ", ownerId: "owner" });
const initialVersion = await projects.version(projectGroupRef(project.id));
assert.equal(project.name, "Launch Cohort");
@@ -84,7 +86,7 @@ test("session lists check each project once per request and observe membership c
test("ProjectStore rename is owner-only and cleans the name", async () => {
let at = 100;
- const projects = createProjectStore(undefined, { id: () => "pr", now: () => at++ });
+ const projects = createProjectStore(createMemoryMap(), { ...singleProcessDeps(), id: () => "pr", now: () => at++ });
const project = await projects.create({ name: "Before", ownerId: "owner" });
const versionBefore = await projects.version(projectGroupRef(project.id));
assert.equal((await projects.rename(project.id, "mallory", "Hijacked")).status, "forbidden");
@@ -106,7 +108,7 @@ test("ProjectStore rename is owner-only and cleans the name", async () => {
test("ProjectStore slack-channel link is member-managed and not a roster change", async () => {
let at = 500;
- const projects = createProjectStore(undefined, { id: () => "sl", now: () => at++ });
+ const projects = createProjectStore(createMemoryMap(), { ...singleProcessDeps(), id: () => "sl", now: () => at++ });
const project = await projects.create({ name: "Linked", ownerId: "owner" });
await projects.addMember(project.id, "owner", "member");
const groupRef = projectGroupRef(project.id);
@@ -149,7 +151,7 @@ test("ProjectStore slack-channel link is member-managed and not a roster change"
test("ProjectStore derives membership from the linked channel roster", async () => {
let at = 900;
- const projects = createProjectStore(undefined, { id: () => "dr", now: () => at++ });
+ const projects = createProjectStore(createMemoryMap(), { ...singleProcessDeps(), id: () => "dr", now: () => at++ });
const project = await projects.create({ name: "Derived", ownerId: "owner" });
const groupRef = projectGroupRef(project.id);
@@ -186,7 +188,7 @@ test("ProjectStore derives membership from the linked channel roster", async ()
});
test("managed groups override Slack membership and historical sessions grant no access", async () => {
- const projects = createProjectStore(undefined, { id: () => "managed" });
+ const projects = createProjectStore(createMemoryMap(), { ...singleProcessDeps(), id: () => "managed" });
const project = await projects.create({ name: "Managed", ownerId: "owner" });
const managedScope = projectScopeId(project.id);
const deps = {
@@ -449,6 +451,7 @@ test("Project routes use ordinary group sessions with the durable roster as auth
assert.equal(forgedApproval.status, "refused");
const deployAcl = createAclStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/prompt-modes.test.ts b/test/prompt-modes.test.ts
index 6b1bf9c2c..b7867cd84 100644
--- a/test/prompt-modes.test.ts
+++ b/test/prompt-modes.test.ts
@@ -25,6 +25,7 @@ import type { ConnectorStatusCache } from "../src/credentials/connector-status.t
import type { ConnectorTokenStore } from "../src/credentials/keychain.ts";
import type { SkillStore } from "../src/skills/skill-store.ts";
import { scopeId, type Conversation, type Principal } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
@@ -89,6 +90,7 @@ async function buildOrchestrator(
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "pm-")));
const memory = createMemoryService(workspace);
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "pm-deploy"),
@@ -103,6 +105,7 @@ async function buildOrchestrator(
}
return createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
sessionSyscalls: opts.sessionSyscalls,
featureFlags: opts.featureFlags,
diff --git a/test/publish-default-audience.test.ts b/test/publish-default-audience.test.ts
index 627283e5e..2fe0bb7a5 100644
--- a/test/publish-default-audience.test.ts
+++ b/test/publish-default-audience.test.ts
@@ -10,6 +10,7 @@ import { createAclStore, type AclStore } from "../src/acl/acl-store.ts";
import { createMemoryConfigStore, type ScopedConfigStore } from "../src/resolution/config-store.ts";
import type { Sandbox, SandboxHandle } from "../src/sandbox/sandbox.ts";
import { scopeId, type ConversationKind, type Principal } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
const orgScope = scopeId("org", ORG);
@@ -19,6 +20,7 @@ function svc() {
const deployStore: DeployStore = createDeployStore();
const acl: AclStore = createAclStore();
const deploy: DeployService = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/publish-primitive.test.ts b/test/publish-primitive.test.ts
index 4f751626c..65232e585 100644
--- a/test/publish-primitive.test.ts
+++ b/test/publish-primitive.test.ts
@@ -12,12 +12,14 @@ import type { ToolLedger } from "../src/runs/tool-ledger.ts";
import { CapabilityUnsupportedError } from "../src/sandbox/sandbox.ts";
import type { AgentComputerExportEntry, Sandbox, SandboxHandle } from "../src/sandbox/sandbox.ts";
import { scopeId } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function svc() {
const deployStore: DeployStore = createDeployStore();
const acl: AclStore = createAclStore();
let starts = 0;
const deploy: DeployService = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/reach-deployment.test.ts b/test/reach-deployment.test.ts
index a3271e4a9..bb19b334d 100644
--- a/test/reach-deployment.test.ts
+++ b/test/reach-deployment.test.ts
@@ -15,11 +15,13 @@ import { createMemorySessionStore } from "../src/sessions/memory-session-store.t
import { scopeId } from "../src/types.ts";
import { signedRequestHeaders } from "../plugins/chassis/src/source-auth-sign.ts";
import { verifyDeployGitAccess } from "../src/deploy/access-token.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function appWithFakeRuntime() {
const deployStore = createDeployStore();
const acl: AclStore = createAclStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore,
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/refusal-admin-link-integration.test.ts b/test/refusal-admin-link-integration.test.ts
index 35245b3b6..44cca728f 100644
--- a/test/refusal-admin-link-integration.test.ts
+++ b/test/refusal-admin-link-integration.test.ts
@@ -27,6 +27,7 @@ import type { SessionStore } from "../src/sessions/session-store.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
import type { Conversation, Principal } from "../src/types.ts";
import { refusalNote } from "../src/slack/lib.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
const ADMIN = "https://portal.example.com";
@@ -60,6 +61,7 @@ function buildOrchestrator(sessions: SessionStore) {
const auditLog = createAuditLog();
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "ral-")));
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "ral-deploy"),
@@ -67,6 +69,7 @@ function buildOrchestrator(sessions: SessionStore) {
acl,
});
return createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
resolution: createResolutionService(ORG, config, acl),
sessions,
diff --git a/test/reply-detection-failure.test.ts b/test/reply-detection-failure.test.ts
index a7cb17978..0155edea7 100644
--- a/test/reply-detection-failure.test.ts
+++ b/test/reply-detection-failure.test.ts
@@ -24,6 +24,7 @@ import { createMemoryDurableByteStore } from "../src/files/durable-byte-store.ts
import type { Harness } from "../src/harness/harness.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
import type { Conversation, Principal } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const actor: Principal = { id: "U1", type: "internal" };
@@ -52,6 +53,7 @@ test("an ambient message whose reply detection fails stays silent and leaves the
const errors = createErrorLog();
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "rdf-")));
const orch = createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
resolution: createResolutionService("default-org", config, acl),
sessions: createMemorySessionStore(),
@@ -67,6 +69,7 @@ test("an ambient message whose reply detection fails stays silent and leaves the
harness,
memory: createMemoryService(workspace),
deploy: createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "rdf-deploy"),
diff --git a/test/resume-surface-post.test.ts b/test/resume-surface-post.test.ts
index dc5e0df1d..8e70e4590 100644
--- a/test/resume-surface-post.test.ts
+++ b/test/resume-surface-post.test.ts
@@ -25,6 +25,7 @@ import { createDeliveryStore } from "../src/delivery/delivery-store.ts";
import type { DeliveryStore } from "../src/delivery/delivery-store.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
import type { Conversation, Principal } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
const actor: Principal = { id: "U1", type: "internal" };
@@ -61,6 +62,7 @@ function buildOrchestrator(
const auditLog = createAuditLog();
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "rsp-")));
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "rsp-deploy"),
@@ -68,6 +70,7 @@ function buildOrchestrator(
acl,
});
return createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
resolution: createResolutionService(ORG, config, acl),
sessions,
diff --git a/test/sandbox-destroy-scope.test.ts b/test/sandbox-destroy-scope.test.ts
index dbc11e43d..650e02971 100644
--- a/test/sandbox-destroy-scope.test.ts
+++ b/test/sandbox-destroy-scope.test.ts
@@ -19,6 +19,9 @@ import { installFakeSmolmachines } from "./support/fake-smolmachines.ts";
import { installFakeSprites } from "./support/fake-sprites.ts";
import { installFakeAgent37 } from "./support/fake-agent37.ts";
import { installFakeDocker } from "./support/fake-docker.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const workspace = () => createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "destroy-scope-")));
@@ -61,7 +64,12 @@ test("Local scope deletion fails a refused core disconnect only while the core i
test("Sprites scope deletion sends only DELETE, retries provider errors, and accepts missing bodies", async () => {
const fake = installFakeSprites();
try {
- const sandbox = createSpritesSandbox(workspace(), { token: "test", baseUrl: fake.baseUrl });
+ const sandbox = createSpritesSandbox(workspace(), {
+ initializationStore: createMemoryMap(),
+ advisoryLock: createMemoryAdvisoryLock(),
+ token: "test",
+ baseUrl: fake.baseUrl,
+ });
await sandbox.provision([{ scopeId: "scope", mountPath: "", mode: "rw" }]);
fake.calls.length = 0;
fake.refuseDelete(503);
@@ -89,6 +97,8 @@ for (const [name, create, resource] of [
let status = 503;
let exists = true;
const sandbox = create(workspace(), {
+ ...singleProcessDeps(),
+ store: createMemoryMap(),
token: "test",
fetchImpl: async (input, init) => {
const path = new URL(String(input)).pathname;
@@ -141,9 +151,9 @@ for (const [name, create, install] of [
test(`${name} stale adapter deletes another adapter's replacement for the same scope`, async () => {
const fake = install();
try {
- const options = { token: "test-token", fetchImpl: fake.fetchImpl };
- const a = create(workspace(), options);
- const b = create(workspace(), options);
+ const options = { ...singleProcessDeps(), token: "test-token", fetchImpl: fake.fetchImpl };
+ const a = create(workspace(), { ...options, store: createMemoryMap() });
+ const b = create(workspace(), { ...options, store: createMemoryMap() });
const layers = [{ scopeId: "replaced", mountPath: "", mode: "rw" as const }];
await a.provision(layers);
await b.destroyScope!("replaced");
diff --git a/test/sandbox-noninteractive.test.ts b/test/sandbox-noninteractive.test.ts
index 04df8c946..25301aef3 100644
--- a/test/sandbox-noninteractive.test.ts
+++ b/test/sandbox-noninteractive.test.ts
@@ -8,6 +8,8 @@ import { createLocalWorkspaceStore } from "../src/workspace/workspace-store.ts";
import { scopeId } from "../src/types.ts";
import { nonInteractiveShellPrefix, NONINTERACTIVE_ENV } from "../src/sandbox/sandbox-env.ts";
import { installFakeSprites, type FakeSprites } from "./support/fake-sprites.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
let ff: FakeSprites;
before(() => {
@@ -18,6 +20,8 @@ after(() => ff.cleanup());
function spritesHandle(env?: Record<string, string>) {
const dir = mkdtempSync(join(tmpdir(), "noninteractive-"));
const sandbox = createSpritesSandbox(createLocalWorkspaceStore(dir), {
+ initializationStore: createMemoryMap(),
+ advisoryLock: createMemoryAdvisoryLock(),
token: "test-token",
baseUrl: ff.baseUrl,
});
diff --git a/test/save-login.test.ts b/test/save-login.test.ts
index 4189a6921..e5637d1b3 100644
--- a/test/save-login.test.ts
+++ b/test/save-login.test.ts
@@ -11,12 +11,14 @@ import { createKeychain } from "../src/credentials/keychain.ts";
import { createMemoryMap } from "../src/persistence/durable-map.ts";
import { deriveConnectorKey } from "../src/connectors/connector-client-store.ts";
import { scopeId } from "../src/types.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const run = promisify(execFile);
const script = fileURLToPath(new URL("../skills-seed/interactive-login/scripts/save-login.mjs", import.meta.url));
test("save-login uploads a private login home and re-saving keeps the entry and its grants", async (t) => {
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/secret-schema-drift.test.ts b/test/secret-schema-drift.test.ts
index 46aa7f40c..952c56642 100644
--- a/test/secret-schema-drift.test.ts
+++ b/test/secret-schema-drift.test.ts
@@ -127,6 +127,7 @@ test("production rejects weak encryption key material for managed credentials",
CORE_SIGNING_SECRET: strong,
PORTAL_IDENTITY_SECRET: "identity",
SKILL_SIGNING_SECRET: strong,
+ DATABASE_URL: "postgres://qm@localhost/qm",
} as NodeJS.ProcessEnv;
assert.deepEqual(validateCoreSecretEnv(env), []);
assert.deepEqual(validateCoreSecretEnv({ ...env, CONNECTOR_SECRET_KEY: "short" }), ["CONNECTOR_SECRET_KEY"]);
diff --git a/test/service-credential-store.test.ts b/test/service-credential-store.test.ts
index 6974af2bd..42e3088d0 100644
--- a/test/service-credential-store.test.ts
+++ b/test/service-credential-store.test.ts
@@ -4,12 +4,14 @@ import { scopeId } from "../src/types.ts";
import { createKeychain, isValidCredentialSlug, type KeychainCredential } from "../src/credentials/keychain.ts";
import { createMemoryMap, type DurableMap } from "../src/persistence/durable-map.ts";
import { deriveConnectorKey } from "../src/connectors/connector-client-store.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const ORG = scopeId("org", "default-org");
const KEY = deriveConnectorKey("test-connector-key-aaaaaaaaaaaaaaaa");
function store(opts: { creds?: DurableMap<KeychainCredential> } = {}) {
return createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: opts.creds ?? createMemoryMap<KeychainCredential>(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/session-mail-approval.test.ts b/test/session-mail-approval.test.ts
index e358cb894..01db03abd 100644
--- a/test/session-mail-approval.test.ts
+++ b/test/session-mail-approval.test.ts
@@ -31,6 +31,7 @@ import { createFeatureFlagStore } from "../src/feature-flags.ts";
import { createSessionMailbox, type SessionMessage } from "../src/sessions/session-mailbox.ts";
import { createSessionSyscalls } from "../src/sessions/session-syscalls.ts";
import { createMemoryRunSignalStore } from "../src/runs/run-signal-store.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function fakeSandbox(): Sandbox {
const unreached = () => {
@@ -103,6 +104,7 @@ async function scenario() {
const auditLog = createAuditLog();
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "session-mail-")));
const orchestrator = createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
resolution: createResolutionService(ORG, createMemoryConfigStore(ORG), acl),
sessions,
@@ -116,6 +118,7 @@ async function scenario() {
harness,
memory: createMemoryService(workspace),
deploy: createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "session-mail-deploy"),
diff --git a/test/share-deployment.test.ts b/test/share-deployment.test.ts
index 5dd542fb7..02539c371 100644
--- a/test/share-deployment.test.ts
+++ b/test/share-deployment.test.ts
@@ -28,6 +28,7 @@ import type { RecipientResolution } from "../src/directory/directory-store.ts";
import type { Sandbox, SandboxHandle } from "../src/sandbox/sandbox.ts";
import { scopeId } from "../src/types.ts";
import type { FeatureFlagStore } from "../src/feature-flags.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const externalSharingOn = { enabled: async () => true } as unknown as FeatureFlagStore;
@@ -40,6 +41,7 @@ function makeDeploy(
): { deploy: DeployService; acl: AclStore } {
const acl: AclStore = createAclStore();
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: {
profile: { managedScaleToZero: false },
diff --git a/test/shared-credential-resumption.test.ts b/test/shared-credential-resumption.test.ts
index 3b204c360..bfeb6581f 100644
--- a/test/shared-credential-resumption.test.ts
+++ b/test/shared-credential-resumption.test.ts
@@ -11,9 +11,11 @@ import { fireAskResolution, type AskResolutionDeps } from "../src/triggers/keych
import { runTrigger } from "../src/triggers/run-trigger.ts";
import type { Principal, ScopeId, TurnRequest } from "../src/types.ts";
import { materializeGrant } from "./support/materialize-grant.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
function keychain(now = Date.now) {
return createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/skill-sync-engine.test.ts b/test/skill-sync-engine.test.ts
index d05874a41..1084eb76a 100644
--- a/test/skill-sync-engine.test.ts
+++ b/test/skill-sync-engine.test.ts
@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
import { createSkillPackStore, type NewSkillPack } from "../src/skills/skill-pack-store.ts";
import { createSkillSyncEngine } from "../src/skills/skill-sync-engine.ts";
import type { SkillPackFetcher } from "../src/skills/pack-fetcher.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const base: NewSkillPack = {
kind: "git",
@@ -34,6 +35,7 @@ test("tracked pack: fast-path skips reconcile when HEAD == last good commit", as
await packs.recordImport(s.id, { at: 0, commit: "c1", status: "ok" });
const calls: string[] = [];
const engine = createSkillSyncEngine({
+ ...singleProcessDeps(),
packs,
fetcher: fakeFetcher({ [s.id]: "c1" }),
reconcile: async (id) => void calls.push(id),
@@ -48,6 +50,7 @@ test("tracked pack: reconciles when HEAD has advanced", async () => {
await packs.recordImport(s.id, { at: 0, commit: "c1", status: "ok" });
const calls: string[] = [];
const engine = createSkillSyncEngine({
+ ...singleProcessDeps(),
packs,
fetcher: fakeFetcher({ [s.id]: "c2" }),
reconcile: async (id) => void calls.push(id),
@@ -62,6 +65,7 @@ test("pinned pack: sets updateAvailable when the line advanced past the pinned c
await packs.recordImport(s.id, { at: 0, commit: "c1", status: "ok" });
const calls: string[] = [];
const engine = createSkillSyncEngine({
+ ...singleProcessDeps(),
packs,
fetcher: fakeFetcher({ [s.id]: "c2" }),
reconcile: async (id) => void calls.push(id),
@@ -76,7 +80,12 @@ test("pinned pack: clears a stale updateAvailable when HEAD == pinned commit", a
const s = await packs.create({ ...base, syncMode: "pinned", ref: "c1" });
await packs.recordImport(s.id, { at: 0, commit: "c1", status: "ok" });
await packs.update(s.id, { updateAvailable: true });
- const engine = createSkillSyncEngine({ packs, fetcher: fakeFetcher({ [s.id]: "c1" }), reconcile: async () => {} });
+ const engine = createSkillSyncEngine({
+ ...singleProcessDeps(),
+ packs,
+ fetcher: fakeFetcher({ [s.id]: "c1" }),
+ reconcile: async () => {},
+ });
await engine.tick();
assert.equal((await packs.get(s.id))?.updateAvailable, false, "no advance ⇒ flag cleared");
});
@@ -89,6 +98,7 @@ test("one failing pack never aborts the tick", async () => {
await packs.recordImport(good.id, { at: 0, commit: "c1", status: "ok" });
const calls: string[] = [];
const engine = createSkillSyncEngine({
+ ...singleProcessDeps(),
packs,
fetcher: fakeFetcher({ [good.id]: "c2" }),
reconcile: async (id) => void calls.push(id),
diff --git a/test/smolmachines-sandbox.test.ts b/test/smolmachines-sandbox.test.ts
index 04a537c89..8f6e2d0e2 100644
--- a/test/smolmachines-sandbox.test.ts
+++ b/test/smolmachines-sandbox.test.ts
@@ -40,6 +40,8 @@ const preCreate = (name: string): Promise<Response> =>
function make(extra: Record<string, unknown> = {}): Sandbox {
return createSmolmachinesSandbox(createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "smol-ws-"))), {
+ store: createMemoryMap(),
+ advisoryLock: createMemoryAdvisoryLock(),
token: FAKE_SMOLMACHINES_TOKEN,
namePrefix: "qmt",
fetchImpl: fake.fetchImpl,
diff --git a/test/sprites-sandbox.test.ts b/test/sprites-sandbox.test.ts
index a742744ef..17767e5fd 100644
--- a/test/sprites-sandbox.test.ts
+++ b/test/sprites-sandbox.test.ts
@@ -33,6 +33,8 @@ const layers = [{ scopeId: scope, mountPath: "/", mode: "rw" as const }];
function make(extra: Record<string, unknown> = {}): Sandbox {
return createSpritesSandbox(createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "sprites-ws-"))), {
+ initializationStore: createMemoryMap(),
+ advisoryLock: createMemoryAdvisoryLock(),
token: FAKE_SPRITES_TOKEN,
namePrefix: "qmt",
baseUrl: fake.baseUrl,
diff --git a/test/subagent-parity.test.ts b/test/subagent-parity.test.ts
index bab8403e1..9c5ac5865 100644
--- a/test/subagent-parity.test.ts
+++ b/test/subagent-parity.test.ts
@@ -35,6 +35,7 @@ import { createMemoryRunSignalStore } from "../src/runs/run-signal-store.ts";
import { scopeId, type Principal, type Session } from "../src/types.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
import type { Run } from "../src/runs/run-store.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
type Call = { tool: string; args: Record<string, unknown> };
type Turn = {
@@ -138,6 +139,7 @@ async function world(flags: FeatureName[], next: (turn: Turn, subagent: boolean)
await config.setApprovedHarnesses(["pi", "claude"]);
await config.setInteractiveFastMode(true);
const orchestrator = createOrchestrator({
+ ...singleProcessDeps(),
config,
runtime: createRuntimeService(
{ config, harnessId: "pi", baseModelDefault: "claude-opus-5" },
@@ -156,6 +158,7 @@ async function world(flags: FeatureName[], next: (turn: Turn, subagent: boolean)
harness,
memory: createMemoryService(workspace),
deploy: createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "subagent-parity-deploy"),
diff --git a/test/suggested-activities.test.ts b/test/suggested-activities.test.ts
index 1c784e1d1..4ab8beb5e 100644
--- a/test/suggested-activities.test.ts
+++ b/test/suggested-activities.test.ts
@@ -9,6 +9,7 @@ import { createDeliveryStore } from "../src/delivery/delivery-store.ts";
import { createIdempotencyStore } from "../src/idempotency/idempotency-store.ts";
import { createIdentityService } from "../src/identity/identity-service.ts";
import { scopeId, type TurnRequest } from "../src/types.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const activities = ["app", "brief", "deck"].map((id) => ({
id,
@@ -27,6 +28,7 @@ function fixture() {
const calls: TurnRequest[] = [];
const settled: Promise<void>[] = [];
const scheduler = createScheduler({
+ ...singleProcessDeps(),
crons,
deliveries,
identity: createIdentityService(),
diff --git a/test/superserve-sandbox.test.ts b/test/superserve-sandbox.test.ts
index a2f41ef17..fd4ff8699 100644
--- a/test/superserve-sandbox.test.ts
+++ b/test/superserve-sandbox.test.ts
@@ -20,6 +20,7 @@ import { scopeId } from "../src/types.ts";
import { shq } from "../src/util/shell.ts";
import { installFakeSuperserve, type FakeSuperserve } from "./support/fake-superserve.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
let fake: FakeSuperserve;
let sandbox: Sandbox;
@@ -36,8 +37,11 @@ const scopeName = (): string => sandboxScopeName("qmt", scope);
function make(extra: Record<string, unknown> = {}): Sandbox {
return createSuperserveSandbox(newWorkspace(), {
+ store: createMemoryMap(),
+ ...singleProcessDeps(),
client: fake.client,
namePrefix: "qmt",
+ configEpoch: 1,
...extra,
});
}
@@ -408,8 +412,8 @@ test("concurrent cores serialize read-only layer preparation", async () => {
create: async (...args: Parameters<typeof fake.client.create>) => wrap(await fake.client.create(...args)),
connect: async (...args: Parameters<typeof fake.client.connect>) => wrap(await fake.client.connect(...args)),
};
- const first = createSuperserveSandbox(workspace, { client, advisoryLock, configEpoch: 1 });
- const second = createSuperserveSandbox(workspace, { client, advisoryLock, configEpoch: 1 });
+ const first = createSuperserveSandbox(workspace, { store: createMemoryMap(), client, advisoryLock, configEpoch: 1 });
+ const second = createSuperserveSandbox(workspace, { store: createMemoryMap(), client, advisoryLock, configEpoch: 1 });
const results = await Promise.allSettled([first.provision(layered), second.provision(layered)]);
assert.equal(overlappingWrites, false, "each core owns the shared archive until extraction finishes");
assert.deepEqual(
@@ -426,8 +430,18 @@ test("an older core leaves newer read-only layers intact", async () => {
await newerWorkspace.write(shared, "policy.txt", "new");
const layered = [...layers, { scopeId: shared, mountPath: "global", mode: "ro" as const }];
const advisoryLock = createMemoryAdvisoryLock();
- const older = createSuperserveSandbox(olderWorkspace, { client: fake.client, advisoryLock, configEpoch: 1 });
- const newer = createSuperserveSandbox(newerWorkspace, { client: fake.client, advisoryLock, configEpoch: 2 });
+ const older = createSuperserveSandbox(olderWorkspace, {
+ store: createMemoryMap(),
+ client: fake.client,
+ advisoryLock,
+ configEpoch: 1,
+ });
+ const newer = createSuperserveSandbox(newerWorkspace, {
+ store: createMemoryMap(),
+ client: fake.client,
+ advisoryLock,
+ configEpoch: 2,
+ });
await older.provision(layered);
const upgraded = await newer.provision(layered);
const held = await older.provision(layered);
@@ -588,22 +602,39 @@ test("a newer core stamps its epoch even when only lifecycle settings changed",
test("the config epoch is claimed once per deployment generation, so a restarted core cannot outrank a newer one", async () => {
const epochs: DurableMap<StoredConfigEpoch> = createMemoryMap();
- const claimed = await createConfigEpochResolver(epochs, "release-1")();
+ const claimed = await createConfigEpochResolver(epochs, "release-1", singleProcessDeps().advisoryLock)();
assert.equal(claimed, 1);
- assert.equal(await createConfigEpochResolver(epochs, "release-1")(), claimed, "a restart reuses its own generation");
- const newRelease = await createConfigEpochResolver(epochs, "release-2")();
+ assert.equal(
+ await createConfigEpochResolver(epochs, "release-1", singleProcessDeps().advisoryLock)(),
+ claimed,
+ "a restart reuses its own generation",
+ );
+ const newRelease = await createConfigEpochResolver(epochs, "release-2", singleProcessDeps().advisoryLock)();
assert.equal(newRelease, claimed + 1, "each new generation is strictly higher than every generation before it");
- assert.equal(await createConfigEpochResolver(epochs, "release-1")(), claimed, "a restart still ranks below it");
+ assert.equal(
+ await createConfigEpochResolver(epochs, "release-1", singleProcessDeps().advisoryLock)(),
+ claimed,
+ "a restart still ranks below it",
+ );
- const older = make({ configEpoch: createConfigEpochResolver(epochs, "release-1"), idlePauseSec: 600 });
+ const older = make({
+ configEpoch: createConfigEpochResolver(epochs, "release-1", singleProcessDeps().advisoryLock),
+ idlePauseSec: 600,
+ });
await older.teardown(await older.provision(layers));
assert.equal(fake.current(scopeName())?.metadata[SUPERSERVE_METADATA.epoch], String(claimed));
- const newer = make({ configEpoch: createConfigEpochResolver(epochs, "release-2"), idlePauseSec: 1_800 });
+ const newer = make({
+ configEpoch: createConfigEpochResolver(epochs, "release-2", singleProcessDeps().advisoryLock),
+ idlePauseSec: 1_800,
+ });
await newer.teardown(await newer.provision(layers));
assert.equal(fake.current(scopeName())?.timeoutSeconds, 1_800);
- const restarted = make({ configEpoch: createConfigEpochResolver(epochs, "release-1"), idlePauseSec: 600 });
+ const restarted = make({
+ configEpoch: createConfigEpochResolver(epochs, "release-1", singleProcessDeps().advisoryLock),
+ idlePauseSec: 600,
+ });
await restarted.teardown(await restarted.provision(layers));
assert.equal(fake.current(scopeName())?.timeoutSeconds, 1_800, "the restarted older release stays passive");
assert.equal(fake.current(scopeName())?.metadata[SUPERSERVE_METADATA.epoch], String(newRelease));
diff --git a/test/support/single-process.ts b/test/support/single-process.ts
new file mode 100644
index 000000000..e59aa0783
--- /dev/null
+++ b/test/support/single-process.ts
@@ -0,0 +1,13 @@
+import { createNoopAdvisoryLock } from "../../src/persistence/advisory-lock.ts";
+import { createNoopLeaderLease } from "../../src/persistence/leader-lease.ts";
+import { createMemoryMap } from "../../src/persistence/durable-map.ts";
+import { createMemoryBlobTransferStore } from "../../src/persistence/blob-transfer.ts";
+import type { CommandApprovalGrant, PendingApprovalRecord } from "../../src/types.ts";
+
+export const singleProcessDeps = () => ({
+ advisoryLock: createNoopAdvisoryLock(),
+ leaderLease: createNoopLeaderLease(),
+ approvals: createMemoryMap<PendingApprovalRecord>(),
+ approvalGrants: createMemoryMap<CommandApprovalGrant>(),
+ blobTransfer: createMemoryBlobTransferStore(),
+});
diff --git a/test/swarm-modal.test.ts b/test/swarm-modal.test.ts
index 91784e387..079073cfa 100644
--- a/test/swarm-modal.test.ts
+++ b/test/swarm-modal.test.ts
@@ -9,6 +9,8 @@ import type { ModalClient, ModalSession } from "../src/sandbox/modal-client.ts";
import { installFakeModal } from "./support/fake-modal.ts";
import { instrumentedSnapshotStore } from "./support/snapshot-stores.ts";
import { swarmFixture } from "./support/swarm-fixture.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
+import { createMemoryMap } from "../src/persistence/durable-map.ts";
test("real Modal adapter creates blank worker computers without snapshot or restore calls", async () => {
const fake = installFakeModal({ native: true });
@@ -36,6 +38,8 @@ test("real Modal adapter creates blank worker computers without snapshot or rest
},
};
const backend = createModalSandbox(createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "swarm-modal-"))), {
+ store: createMemoryMap(),
+ ...singleProcessDeps(),
client,
snapshots: snapshotStore.store,
nativeSnapshotsEnabled: true,
diff --git a/test/system-prompt-order.test.ts b/test/system-prompt-order.test.ts
index 975e23320..db2a2903d 100644
--- a/test/system-prompt-order.test.ts
+++ b/test/system-prompt-order.test.ts
@@ -33,6 +33,7 @@ import { createSkillStore, type SkillStore } from "../src/skills/skill-store.ts"
import { scopeId, type Conversation, type Principal, type ScopeId, type TurnRequest } from "../src/types.ts";
import type { ManagedGroupDirectory } from "../src/resolution/scope-membership.ts";
import type { IsCurrentSharedScopeMember } from "../src/resolution/scope-membership.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
const actor: Principal = { id: "U1", type: "internal" };
@@ -106,6 +107,7 @@ function buildOrchestrator(
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "spo-")));
const memory = createMemoryService(workspace);
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "spo-deploy"),
@@ -115,6 +117,7 @@ function buildOrchestrator(
const sessions = createMemorySessionStore();
const files = createMemoryFileArtifactStore(createMemoryDurableByteStore());
const orchestrator = createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
resolution: createResolutionService(ORG, config, acl),
sessions,
diff --git a/test/tool-call-resume.test.ts b/test/tool-call-resume.test.ts
index acedd9346..bd72f6a36 100644
--- a/test/tool-call-resume.test.ts
+++ b/test/tool-call-resume.test.ts
@@ -29,6 +29,7 @@ import { createDeliveryStore } from "../src/delivery/delivery-store.ts";
import type { ToolContext } from "../src/tools/primitives.ts";
import { scopeId, type Conversation, type Principal, type SessionEntry } from "../src/types.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
const actor: Principal = { id: "U1", type: "internal" };
@@ -256,6 +257,7 @@ function buildScenario() {
const auditLog = createAuditLog();
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "tool-call-resume-")));
const orchestrator = createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
resolution: createResolutionService(ORG, createMemoryConfigStore(ORG), acl),
sessions,
@@ -269,6 +271,7 @@ function buildScenario() {
harness,
memory: createMemoryService(workspace),
deploy: createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "tool-call-resume-deploy"),
diff --git a/test/turn-bookkeeping-failures.test.ts b/test/turn-bookkeeping-failures.test.ts
index 5fbc6ae27..6aa6d5161 100644
--- a/test/turn-bookkeeping-failures.test.ts
+++ b/test/turn-bookkeeping-failures.test.ts
@@ -24,6 +24,7 @@ import { createDeliveryStore } from "../src/delivery/delivery-store.ts";
import { scopeId, type Conversation, type Principal } from "../src/types.ts";
import type { HarnessTurnResult } from "../src/harness/harness.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
const actor: Principal = { id: "U1", type: "internal" };
@@ -78,6 +79,7 @@ function buildScenario(turnResult?: Partial<HarnessTurnResult>) {
const auditLog = createAuditLog();
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "bookkeeping-")));
const deploy = createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "bookkeeping-deploy"),
@@ -86,6 +88,7 @@ function buildScenario(turnResult?: Partial<HarnessTurnResult>) {
});
const deliveries = createDeliveryStore();
const orchestrator = createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
resolution: createResolutionService(ORG, createMemoryConfigStore(ORG), acl),
sessions,
diff --git a/test/turn-retry-replay.test.ts b/test/turn-retry-replay.test.ts
index 521a2eaa7..7b1d9360e 100644
--- a/test/turn-retry-replay.test.ts
+++ b/test/turn-retry-replay.test.ts
@@ -24,6 +24,7 @@ import { createDeployService } from "../src/deploy/deploy-service.ts";
import { createDeliveryStore } from "../src/delivery/delivery-store.ts";
import { scopeId, type Conversation, type Principal, type SessionEntry } from "../src/types.ts";
import type { Sandbox } from "../src/sandbox/sandbox.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const ORG = "default-org";
const actor: Principal = { id: "U1", type: "internal" };
@@ -106,6 +107,7 @@ function buildScenario(interruptAfterToolResult = false) {
const auditLog = createAuditLog();
const workspace = createLocalWorkspaceStore(mkdtempSync(join(tmpdir(), "retry-replay-")));
const orchestrator = createOrchestrator({
+ ...singleProcessDeps(),
identity: createIdentityService(),
resolution: createResolutionService(ORG, createMemoryConfigStore(ORG), acl),
sessions,
@@ -119,6 +121,7 @@ function buildScenario(interruptAfterToolResult = false) {
harness,
memory: createMemoryService(workspace),
deploy: createDeployService({
+ ...singleProcessDeps(),
deployStore: createDeployStore(),
provider: createDockerDeployProvider(),
deployDir: join(tmpdir(), "retry-replay-deploy"),
diff --git a/test/user-model-auth-injection.test.ts b/test/user-model-auth-injection.test.ts
index cc289508b..601867598 100644
--- a/test/user-model-auth-injection.test.ts
+++ b/test/user-model-auth-injection.test.ts
@@ -7,6 +7,7 @@ import { createUserModelCredentialStore } from "../src/model/user-model-credenti
import { resolveIndividualAuthRouting } from "../src/core/individual-auth-routing.ts";
import { resolveModel } from "../src/model/pi-models.ts";
import type { UserModelCredential } from "../src/model/user-model-credential-store.ts";
+import { createMemoryAdvisoryLock } from "../src/persistence/advisory-lock.ts";
const apikey = (provider: "anthropic" | "openai", apiKey: string): UserModelCredential => ({
provider,
@@ -30,6 +31,7 @@ const KEY_MATERIAL = "test-key-material-that-is-long-enough";
function testStore() {
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
@@ -101,6 +103,7 @@ test("user model credential store round-trips api key and oauth per user+provide
test("stale subscription tokens refresh once (single-flight) inside the keychain", async () => {
let refreshCalls = 0;
const keychain = createKeychain({
+ lock: createMemoryAdvisoryLock(),
creds: createMemoryMap(),
grants: createMemoryMap(),
asks: createMemoryMap(),
diff --git a/test/wake-sweep.test.ts b/test/wake-sweep.test.ts
index 9b67984e7..bf02a79eb 100644
--- a/test/wake-sweep.test.ts
+++ b/test/wake-sweep.test.ts
@@ -2,6 +2,7 @@ import { test } from "node:test";
import assert from "node:assert/strict";
import { createWakeSweep, type SweepSource } from "../src/wake/sweep.ts";
import { createEngagedRegistry } from "../src/wake/engaged-registry.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
function recordingSource(over: Partial<SweepSource> = {}): { source: SweepSource; swept: string[] } {
const swept: string[] = [];
@@ -20,7 +21,7 @@ function recordingSource(over: Partial<SweepSource> = {}): { source: SweepSource
test("a pass sweeps every engaged session", async () => {
const { source, swept } = recordingSource();
- const sweep = createWakeSweep(source, { intervalMs: 10_000 });
+ const sweep = createWakeSweep(source, { ...singleProcessDeps(), intervalMs: 10_000 });
const res = await sweep.sweep();
assert.deepEqual(swept, ["A"]);
assert.equal(res.swept, 1);
@@ -32,7 +33,7 @@ test("a per-session sweep error is caught, not thrown (a flaky pull must not kil
throw new Error("surface pull failed");
},
});
- const sweep = createWakeSweep(source, { intervalMs: 10_000 });
+ const sweep = createWakeSweep(source, { ...singleProcessDeps(), intervalMs: 10_000 });
await assert.rejects(() => sweep.sweep());
});
@@ -53,7 +54,7 @@ test("nothing engaged ⇒ a pass does no work", async () => {
return [];
},
});
- const sweep = createWakeSweep(source, { intervalMs: 10_000 });
+ const sweep = createWakeSweep(source, { ...singleProcessDeps(), intervalMs: 10_000 });
const res = await sweep.sweep();
assert.deepEqual(swept, []);
assert.equal(res.swept, 0);
diff --git a/test/worker-reaper.test.ts b/test/worker-reaper.test.ts
index b4e77ae4d..8ff9fe8d7 100644
--- a/test/worker-reaper.test.ts
+++ b/test/worker-reaper.test.ts
@@ -17,6 +17,7 @@ import type { Principal } from "../src/types.ts";
import type { RunStore } from "../src/runs/run-store.ts";
import { replayableRequest } from "../src/core/orchestrator/turn-helpers.ts";
import { testConfig } from "./support/test-config.ts";
+import { singleProcessDeps } from "./support/single-process.ts";
const sleep = (ms: number): Promise<void> => new Promise((r) => setTimeout(r, ms));
const actor: Principal = { id: "internal:U1", type: "internal" };
@@ -33,7 +34,7 @@ test("reaper requeues a run whose lease expired (crashed worker)", async () => {
await runs.claim("dead-worker", 10);
await sleep(30);
- const reaper = createReaper(runs, createMemorySessionStore(), { intervalMs: 60_000 });
+ const reaper = createReaper(runs, createMemorySessionStore(), { ...singleProcessDeps(), intervalMs: 60_000 });
const swept = await reaper.sweep();
assert.equal(swept.requeued, 1);
assert.equal(swept.parked, 0);
@@ -63,7 +64,7 @@ test("a run parks once the ERROR budget (error_attempts) is exhausted", async ()
test("repeated lease-expiry reaps requeue forever without spending the error budget", async () => {
const { runs } = createMemoryRunStore();
const r = (await runs.enqueue({ sessionId: "s1", request: turn, maxAttempts: 2 })).run;
- const reaper = createReaper(runs, createMemorySessionStore(), { intervalMs: 60_000 });
+ const reaper = createReaper(runs, createMemorySessionStore(), { ...singleProcessDeps(), intervalMs: 60_000 });
for (let i = 0; i < 5; i++) {
await runs.claim("dead-worker", 10);
@@ -81,7 +82,7 @@ test("repeated lease-expiry reaps requeue forever without spending the error bud
test("with maxClaims set, repeated lease-expiry reaps PARK the poison pill instead of requeuing forever", async () => {
const { runs } = createMemoryRunStore({ maxClaims: 3 });
const r = (await runs.enqueue({ sessionId: "s1", request: turn, maxAttempts: 99 })).run;
- const reaper = createReaper(runs, createMemorySessionStore(), { intervalMs: 60_000 });
+ const reaper = createReaper(runs, createMemorySessionStore(), { ...singleProcessDeps(), intervalMs: 60_000 });
for (let i = 1; i <= 2; i++) {
await runs.claim("dead-worker", 10);
@@ -174,7 +175,7 @@ test("reaping a lease-expired run releases its stranded session lease", async ()
await runs.claim("dead-worker", 10);
await sleep(30);
- const reaper = createReaper(runs, sessions, { intervalMs: 60_000 });
+ const reaper = createReaper(runs, sessions, { ...singleProcessDeps(), intervalMs: 60_000 });
const swept = await reaper.sweep();
assert.equal(swept.requeued, 1);
assert.equal((await runs.get(r.id))?.status, "pending", "expired run is requeued");
@@ -218,7 +219,7 @@ test("a heartbeat landing between SELECT and retire leaves the run AND its sessi
assert.equal(await runs.heartbeat(r.id, claimed!.leaseToken!, 10_000), true, "live worker renews its lease");
- const reaper = createReaper(runs, sessions, { intervalMs: 60_000 });
+ const reaper = createReaper(runs, sessions, { ...singleProcessDeps(), intervalMs: 60_000 });
const swept = await reaper.sweep();
assert.equal(swept.requeued, 0, "the renewed run is not requeued");