@dharma-ai-labs/agent-fabric 0.2.153 → 0.2.155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrapGitScope.test.d.ts +2 -0
- package/dist/bootstrapGitScope.test.d.ts.map +1 -0
- package/dist/bootstrapGitScope.test.js +115 -0
- package/dist/bootstrapGitScope.test.js.map +1 -0
- package/dist/bootstrapHostFiles.d.ts +5 -0
- package/dist/bootstrapHostFiles.d.ts.map +1 -0
- package/dist/bootstrapHostFiles.js +150 -0
- package/dist/bootstrapHostFiles.js.map +1 -0
- package/dist/bootstrapHostFiles.test.d.ts +2 -0
- package/dist/bootstrapHostFiles.test.d.ts.map +1 -0
- package/dist/bootstrapHostFiles.test.js +127 -0
- package/dist/bootstrapHostFiles.test.js.map +1 -0
- package/dist/bootstrapHostScope.d.ts +42 -0
- package/dist/bootstrapHostScope.d.ts.map +1 -0
- package/dist/bootstrapHostScope.js +224 -0
- package/dist/bootstrapHostScope.js.map +1 -0
- package/dist/bootstrapHostScope.test.d.ts +2 -0
- package/dist/bootstrapHostScope.test.d.ts.map +1 -0
- package/dist/bootstrapHostScope.test.js +577 -0
- package/dist/bootstrapHostScope.test.js.map +1 -0
- package/dist/bootstrapInstallationScope.test.d.ts +2 -0
- package/dist/bootstrapInstallationScope.test.d.ts.map +1 -0
- package/dist/bootstrapInstallationScope.test.js +68 -0
- package/dist/bootstrapInstallationScope.test.js.map +1 -0
- package/dist/bootstrapLauncherCaller.test.d.ts +2 -0
- package/dist/bootstrapLauncherCaller.test.d.ts.map +1 -0
- package/dist/bootstrapLauncherCaller.test.js +91 -0
- package/dist/bootstrapLauncherCaller.test.js.map +1 -0
- package/dist/bootstrapOwnedChildren.test.d.ts +2 -0
- package/dist/bootstrapOwnedChildren.test.d.ts.map +1 -0
- package/dist/bootstrapOwnedChildren.test.js +93 -0
- package/dist/bootstrapOwnedChildren.test.js.map +1 -0
- package/dist/bootstrapPolicyScope.test.d.ts +2 -0
- package/dist/bootstrapPolicyScope.test.d.ts.map +1 -0
- package/dist/bootstrapPolicyScope.test.js +261 -0
- package/dist/bootstrapPolicyScope.test.js.map +1 -0
- package/dist/bootstrapProcessCaller.test.d.ts +2 -0
- package/dist/bootstrapProcessCaller.test.d.ts.map +1 -0
- package/dist/bootstrapProcessCaller.test.js +262 -0
- package/dist/bootstrapProcessCaller.test.js.map +1 -0
- package/dist/bootstrapRegistryCaller.test.d.ts +2 -0
- package/dist/bootstrapRegistryCaller.test.d.ts.map +1 -0
- package/dist/bootstrapRegistryCaller.test.js +128 -0
- package/dist/bootstrapRegistryCaller.test.js.map +1 -0
- package/dist/bootstrapVaultScope.test.d.ts +2 -0
- package/dist/bootstrapVaultScope.test.d.ts.map +1 -0
- package/dist/bootstrapVaultScope.test.js +105 -0
- package/dist/bootstrapVaultScope.test.js.map +1 -0
- package/dist/codexBootstrapCompletion.test.d.ts +2 -0
- package/dist/codexBootstrapCompletion.test.d.ts.map +1 -0
- package/dist/codexBootstrapCompletion.test.js +630 -0
- package/dist/codexBootstrapCompletion.test.js.map +1 -0
- package/dist/codexBoundSession.d.ts +2 -2
- package/dist/codexBoundSession.d.ts.map +1 -1
- package/dist/codexBoundSession.js +23 -17
- package/dist/codexBoundSession.js.map +1 -1
- package/dist/codexBoundSession.test.js +3 -0
- package/dist/codexBoundSession.test.js.map +1 -1
- package/dist/codexInboxSession.d.ts.map +1 -1
- package/dist/codexInboxSession.js +3 -3
- package/dist/codexInboxSession.js.map +1 -1
- package/dist/codexScopedDispatch.test.d.ts +2 -0
- package/dist/codexScopedDispatch.test.d.ts.map +1 -0
- package/dist/codexScopedDispatch.test.js +56 -0
- package/dist/codexScopedDispatch.test.js.map +1 -0
- package/dist/codexSetupAdmission.d.ts +108 -0
- package/dist/codexSetupAdmission.d.ts.map +1 -0
- package/dist/codexSetupAdmission.js +214 -0
- package/dist/codexSetupAdmission.js.map +1 -0
- package/dist/codexSetupAdmission.test.d.ts +2 -0
- package/dist/codexSetupAdmission.test.d.ts.map +1 -0
- package/dist/codexSetupAdmission.test.js +578 -0
- package/dist/codexSetupAdmission.test.js.map +1 -0
- package/dist/codexSetupChildProvider.test.d.ts +2 -0
- package/dist/codexSetupChildProvider.test.d.ts.map +1 -0
- package/dist/codexSetupChildProvider.test.js +210 -0
- package/dist/codexSetupChildProvider.test.js.map +1 -0
- package/dist/codexSetupChildStartup.d.ts +38 -0
- package/dist/codexSetupChildStartup.d.ts.map +1 -0
- package/dist/codexSetupChildStartup.js +115 -0
- package/dist/codexSetupChildStartup.js.map +1 -0
- package/dist/codexSetupChildStartup.test.d.ts +2 -0
- package/dist/codexSetupChildStartup.test.d.ts.map +1 -0
- package/dist/codexSetupChildStartup.test.js +141 -0
- package/dist/codexSetupChildStartup.test.js.map +1 -0
- package/dist/codexSetupCliDispatch.test.d.ts +2 -0
- package/dist/codexSetupCliDispatch.test.d.ts.map +1 -0
- package/dist/codexSetupCliDispatch.test.js +138 -0
- package/dist/codexSetupCliDispatch.test.js.map +1 -0
- package/dist/codexSetupJournalOpen.test.d.ts +2 -0
- package/dist/codexSetupJournalOpen.test.d.ts.map +1 -0
- package/dist/codexSetupJournalOpen.test.js +101 -0
- package/dist/codexSetupJournalOpen.test.js.map +1 -0
- package/dist/codexSetupNativeHost.d.ts +31 -0
- package/dist/codexSetupNativeHost.d.ts.map +1 -0
- package/dist/codexSetupNativeHost.js +211 -0
- package/dist/codexSetupNativeHost.js.map +1 -0
- package/dist/codexSetupNativeHost.test.d.ts +2 -0
- package/dist/codexSetupNativeHost.test.d.ts.map +1 -0
- package/dist/codexSetupNativeHost.test.js +479 -0
- package/dist/codexSetupNativeHost.test.js.map +1 -0
- package/dist/codexSetupNativeWire.test.d.ts +2 -0
- package/dist/codexSetupNativeWire.test.d.ts.map +1 -0
- package/dist/codexSetupNativeWire.test.js +243 -0
- package/dist/codexSetupNativeWire.test.js.map +1 -0
- package/dist/codexSetupOwnedConnection.d.ts +14 -0
- package/dist/codexSetupOwnedConnection.d.ts.map +1 -0
- package/dist/codexSetupOwnedConnection.js +64 -0
- package/dist/codexSetupOwnedConnection.js.map +1 -0
- package/dist/codexSetupOwnedConnection.test.d.ts +2 -0
- package/dist/codexSetupOwnedConnection.test.d.ts.map +1 -0
- package/dist/codexSetupOwnedConnection.test.js +192 -0
- package/dist/codexSetupOwnedConnection.test.js.map +1 -0
- package/dist/codexSetupPortalCommand.test.d.ts +2 -0
- package/dist/codexSetupPortalCommand.test.d.ts.map +1 -0
- package/dist/codexSetupPortalCommand.test.js +146 -0
- package/dist/codexSetupPortalCommand.test.js.map +1 -0
- package/dist/codexSetupReadiness.d.ts +23 -0
- package/dist/codexSetupReadiness.d.ts.map +1 -0
- package/dist/codexSetupReadiness.js +74 -0
- package/dist/codexSetupReadiness.js.map +1 -0
- package/dist/codexSetupReadiness.test.d.ts +2 -0
- package/dist/codexSetupReadiness.test.d.ts.map +1 -0
- package/dist/codexSetupReadiness.test.js +145 -0
- package/dist/codexSetupReadiness.test.js.map +1 -0
- package/dist/codexSetupSessionCaller.test.d.ts +2 -0
- package/dist/codexSetupSessionCaller.test.d.ts.map +1 -0
- package/dist/codexSetupSessionCaller.test.js +352 -0
- package/dist/codexSetupSessionCaller.test.js.map +1 -0
- package/dist/codexSetupSessionHandoff.d.ts +48 -0
- package/dist/codexSetupSessionHandoff.d.ts.map +1 -0
- package/dist/codexSetupSessionHandoff.js +146 -0
- package/dist/codexSetupSessionHandoff.js.map +1 -0
- package/dist/codexSetupSessionHandoff.test.d.ts +2 -0
- package/dist/codexSetupSessionHandoff.test.d.ts.map +1 -0
- package/dist/codexSetupSessionHandoff.test.js +289 -0
- package/dist/codexSetupSessionHandoff.test.js.map +1 -0
- package/dist/codexSetupTransport.test.d.ts +2 -0
- package/dist/codexSetupTransport.test.d.ts.map +1 -0
- package/dist/codexSetupTransport.test.js +206 -0
- package/dist/codexSetupTransport.test.js.map +1 -0
- package/dist/codexSetupVaultJournal.d.ts +13 -0
- package/dist/codexSetupVaultJournal.d.ts.map +1 -0
- package/dist/codexSetupVaultJournal.js +28 -0
- package/dist/codexSetupVaultJournal.js.map +1 -0
- package/dist/codexSetupVaultJournal.test.d.ts +2 -0
- package/dist/codexSetupVaultJournal.test.d.ts.map +1 -0
- package/dist/codexSetupVaultJournal.test.js +104 -0
- package/dist/codexSetupVaultJournal.test.js.map +1 -0
- package/dist/containerChildCleanup.test.d.ts +2 -0
- package/dist/containerChildCleanup.test.d.ts.map +1 -0
- package/dist/containerChildCleanup.test.js +145 -0
- package/dist/containerChildCleanup.test.js.map +1 -0
- package/dist/containerRelayLifecycle.d.ts +1 -1
- package/dist/containerRelayLifecycle.d.ts.map +1 -1
- package/dist/containerRelayLifecycle.js +29 -37
- package/dist/containerRelayLifecycle.js.map +1 -1
- package/dist/cooperativeInboxSession.d.ts +2 -2
- package/dist/cooperativeInboxSession.d.ts.map +1 -1
- package/dist/cooperativeInboxSession.js +21 -13
- package/dist/cooperativeInboxSession.js.map +1 -1
- package/dist/cooperativeInboxSession.test.js +65 -0
- package/dist/cooperativeInboxSession.test.js.map +1 -1
- package/dist/demoWatchControl.d.ts +3 -3
- package/dist/index.d.ts +55 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1642 -553
- package/dist/index.js.map +1 -1
- package/dist/namedCodexSkillDiscovery.d.ts +15 -0
- package/dist/namedCodexSkillDiscovery.d.ts.map +1 -0
- package/dist/namedCodexSkillDiscovery.js +90 -0
- package/dist/namedCodexSkillDiscovery.js.map +1 -0
- package/dist/namedCodexSkillDiscovery.test.d.ts +2 -0
- package/dist/namedCodexSkillDiscovery.test.d.ts.map +1 -0
- package/dist/namedCodexSkillDiscovery.test.js +37 -0
- package/dist/namedCodexSkillDiscovery.test.js.map +1 -0
- package/dist/namedCodexThread.d.ts +2 -0
- package/dist/namedCodexThread.d.ts.map +1 -1
- package/dist/namedCodexThread.js +13 -4
- package/dist/namedCodexThread.js.map +1 -1
- package/dist/namedSessionChildOwner.d.ts +17 -0
- package/dist/namedSessionChildOwner.d.ts.map +1 -0
- package/dist/namedSessionChildOwner.js +122 -0
- package/dist/namedSessionChildOwner.js.map +1 -0
- package/dist/namedSessionChildOwner.test.d.ts +2 -0
- package/dist/namedSessionChildOwner.test.d.ts.map +1 -0
- package/dist/namedSessionChildOwner.test.js +203 -0
- package/dist/namedSessionChildOwner.test.js.map +1 -0
- package/dist/namedSessionEvidence.d.ts +2 -2
- package/dist/namedSessionEvidence.d.ts.map +1 -1
- package/dist/namedSessionEvidence.js +2 -2
- package/dist/namedSessionEvidence.js.map +1 -1
- package/dist/namedSessionEvidence.test.js +24 -1
- package/dist/namedSessionEvidence.test.js.map +1 -1
- package/dist/namedSessionRepositoryState.d.ts +2 -2
- package/dist/namedSessionRepositoryState.d.ts.map +1 -1
- package/dist/namedSessionService.d.ts +4 -2
- package/dist/namedSessionService.d.ts.map +1 -1
- package/dist/namedSessionService.js +18 -1
- package/dist/namedSessionService.js.map +1 -1
- package/dist/namedSessionService.test.js +31 -2
- package/dist/namedSessionService.test.js.map +1 -1
- package/dist/namedSessionTaskExportSync.d.ts +3 -3
- package/dist/namedSessionTaskExportSync.d.ts.map +1 -1
- package/dist/namedSessionTaskExportSync.js +6 -6
- package/dist/namedSessionTaskExportSync.js.map +1 -1
- package/dist/namedSessionTrust.d.ts +2 -2
- package/dist/namedSessionTrust.d.ts.map +1 -1
- package/dist/namedSessionTrust.js +3 -2
- package/dist/namedSessionTrust.js.map +1 -1
- package/dist/namedSessionTrust.test.js +2 -1
- package/dist/namedSessionTrust.test.js.map +1 -1
- package/dist/ownedChildLifecycle.d.ts +13 -0
- package/dist/ownedChildLifecycle.d.ts.map +1 -0
- package/dist/ownedChildLifecycle.js +87 -0
- package/dist/ownedChildLifecycle.js.map +1 -0
- package/dist/ownedChildLifecycle.test.d.ts +2 -0
- package/dist/ownedChildLifecycle.test.d.ts.map +1 -0
- package/dist/ownedChildLifecycle.test.js +133 -0
- package/dist/ownedChildLifecycle.test.js.map +1 -0
- package/dist/pidLock.test.js +242 -9
- package/dist/pidLock.test.js.map +1 -1
- package/dist/providerSessionChannel.d.ts +1 -1
- package/dist/providerSessionChannel.d.ts.map +1 -1
- package/dist/providerSessionChannel.js +7 -3
- package/dist/providerSessionChannel.js.map +1 -1
- package/dist/providerSessionChannel.test.js +20 -0
- package/dist/providerSessionChannel.test.js.map +1 -1
- package/dist/providerSessionReplyRecovery.d.ts +2 -2
- package/dist/providerSessionReplyRecovery.d.ts.map +1 -1
- package/dist/providerSessionReplyRecovery.js +3 -3
- package/dist/providerSessionReplyRecovery.js.map +1 -1
- package/dist/relayAutostart.d.ts.map +1 -1
- package/dist/relayAutostart.js +12 -9
- package/dist/relayAutostart.js.map +1 -1
- package/dist/relayRuntimeUpgrade.d.ts +1 -1
- package/dist/relaySupervisor.d.ts.map +1 -1
- package/dist/relaySupervisor.js +19 -14
- package/dist/relaySupervisor.js.map +1 -1
- package/dist/relaySupervisor.test.js +26 -0
- package/dist/relaySupervisor.test.js.map +1 -1
- package/dist/relaySupervisorCleanup.test.d.ts +2 -0
- package/dist/relaySupervisorCleanup.test.d.ts.map +1 -0
- package/dist/relaySupervisorCleanup.test.js +69 -0
- package/dist/relaySupervisorCleanup.test.js.map +1 -0
- package/dist/repositoryInstallerFiles.d.ts +19 -1
- package/dist/repositoryInstallerFiles.d.ts.map +1 -1
- package/dist/repositoryInstallerFiles.js +205 -29
- package/dist/repositoryInstallerFiles.js.map +1 -1
- package/dist/repositoryInstallerScope.test.d.ts +2 -0
- package/dist/repositoryInstallerScope.test.d.ts.map +1 -0
- package/dist/repositoryInstallerScope.test.js +513 -0
- package/dist/repositoryInstallerScope.test.js.map +1 -0
- package/dist/repositoryKnowledge.d.ts.map +1 -1
- package/dist/repositoryKnowledge.js +177 -37
- package/dist/repositoryKnowledge.js.map +1 -1
- package/dist/repositoryKnowledgeScope.test.d.ts +2 -0
- package/dist/repositoryKnowledgeScope.test.d.ts.map +1 -0
- package/dist/repositoryKnowledgeScope.test.js +316 -0
- package/dist/repositoryKnowledgeScope.test.js.map +1 -0
- package/dist/repositoryOnboardingCaller.test.js +61 -4
- package/dist/repositoryOnboardingCaller.test.js.map +1 -1
- package/dist/repositoryPackage.d.ts.map +1 -1
- package/dist/repositoryPackage.js +340 -59
- package/dist/repositoryPackage.js.map +1 -1
- package/dist/repositoryPackageDelivery.test.js +65 -0
- package/dist/repositoryPackageDelivery.test.js.map +1 -1
- package/dist/repositoryPackageScope.test.d.ts +2 -0
- package/dist/repositoryPackageScope.test.d.ts.map +1 -0
- package/dist/repositoryPackageScope.test.js +578 -0
- package/dist/repositoryPackageScope.test.js.map +1 -0
- package/dist/schemas/codex-setup-child-start.schema.json +12 -0
- package/dist/schemas/codex-setup-intent.schema.json +27 -0
- package/dist/schemas/local-codex-setup-session.schema.json +39 -0
- package/dist/schemas/setup-claim-failure.schema.json +15 -0
- package/dist/skillInstallationScope.test.d.ts +2 -0
- package/dist/skillInstallationScope.test.d.ts.map +1 -0
- package/dist/skillInstallationScope.test.js +64 -0
- package/dist/skillInstallationScope.test.js.map +1 -0
- package/dist/skillPreparationCache.test.js +12 -4
- package/dist/skillPreparationCache.test.js.map +1 -1
- package/dist/skillPreparationCaller.test.js +31 -1
- package/dist/skillPreparationCaller.test.js.map +1 -1
- package/dist/startupCommitScope.test.d.ts +2 -0
- package/dist/startupCommitScope.test.d.ts.map +1 -0
- package/dist/startupCommitScope.test.js +172 -0
- package/dist/startupCommitScope.test.js.map +1 -0
- package/dist/workspaceRegistry.d.ts.map +1 -1
- package/dist/workspaceRegistry.js +7 -3
- package/dist/workspaceRegistry.js.map +1 -1
- package/dist/workspaceRegistry.test.js +51 -0
- package/dist/workspaceRegistry.test.js.map +1 -1
- package/dist/workspaceRegistryRecovery.d.ts.map +1 -1
- package/dist/workspaceRegistryRecovery.js +171 -64
- package/dist/workspaceRegistryRecovery.js.map +1 -1
- package/dist/workspaceRegistryRecoveryScope.test.d.ts +2 -0
- package/dist/workspaceRegistryRecoveryScope.test.d.ts.map +1 -0
- package/dist/workspaceRegistryRecoveryScope.test.js +416 -0
- package/dist/workspaceRegistryRecoveryScope.test.js.map +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
|
+
import * as syncFs from 'node:fs';
|
|
4
|
+
import * as crypto from 'node:crypto';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import * as url from 'node:url';
|
|
7
|
+
import * as util from 'node:util';
|
|
8
|
+
import { createRequire } from 'node:module';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import { runInNewContext } from 'node:vm';
|
|
11
|
+
import test from 'node:test';
|
|
12
|
+
import ts from 'typescript';
|
|
13
|
+
import * as contracts from '@dharma-ai-labs/agent-fabric-contracts';
|
|
14
|
+
import * as reduction from '@dharma-ai-labs/agent-fabric-evidence-reduction';
|
|
15
|
+
import * as knowledge from './repositoryKnowledge.js';
|
|
16
|
+
import * as authorization from './repositorySourceAuthorization.js';
|
|
17
|
+
import { inventoryRepositoryPackage, serializeRepositoryPackageSnapshot, writeRepositoryPackageSnapshot } from './repositoryPackage.js';
|
|
18
|
+
import { currentBootstrapHostScope, runCodexBootstrapHost } from './bootstrapHostScope.js';
|
|
19
|
+
function host(workspace) {
|
|
20
|
+
const id = (n) => `${String(n).padStart(8, '0')}-1111-4111-8111-111111111111`;
|
|
21
|
+
const now = Date.now(), digest = `sha256:${'a'.repeat(64)}`;
|
|
22
|
+
return { workspace, current: async () => true, signal: new AbortController().signal,
|
|
23
|
+
intent: { schema: 'dharma.codex-setup-intent/v1', operationId: id(1), setupReference: id(2),
|
|
24
|
+
organizationId: 'org_demo', recipientMembershipId: id(3), origin: 'https://hq.example',
|
|
25
|
+
repositoryFingerprint: digest, policyRevision: 'policy-v1', scopeDigest: digest, contractDigest: digest,
|
|
26
|
+
hostContextId: id(4), issuedAt: new Date(now - 1000).toISOString(), expiresAt: new Date(now + 60_000).toISOString() } };
|
|
27
|
+
}
|
|
28
|
+
async function fixture(t) {
|
|
29
|
+
const workspace = await fs.mkdtemp(path.join(tmpdir(), 'dharma-package-scope-'));
|
|
30
|
+
t.after(() => fs.rm(workspace, { recursive: true, force: true }));
|
|
31
|
+
await fs.mkdir(path.join(workspace, '.agents/skills/example'), { recursive: true });
|
|
32
|
+
await fs.writeFile(path.join(workspace, '.agents/skills/example/SKILL.md'), '# Example\nUse logical job identifiers.\n');
|
|
33
|
+
return { workspace, organizationId: 'org_demo', workspaceId: 'synthetic', now: new Date('2026-10-01T00:00:00.000Z') };
|
|
34
|
+
}
|
|
35
|
+
async function module(overrides = {}, inertSchema = false) {
|
|
36
|
+
const location = new URL('../src/repositoryPackage.ts', import.meta.url), require = createRequire(location);
|
|
37
|
+
const source = (await fs.readFile(location, 'utf8')).replaceAll('import.meta.url', JSON.stringify(location.href));
|
|
38
|
+
const result = ts.transpileModule(source, { compilerOptions: { target: ts.ScriptTarget.ES2023,
|
|
39
|
+
module: ts.ModuleKind.CommonJS }, reportDiagnostics: true });
|
|
40
|
+
assert.equal(result.diagnostics?.filter(item => item.category === ts.DiagnosticCategory.Error).length, 0);
|
|
41
|
+
const exports = {};
|
|
42
|
+
runInNewContext(result.outputText, { exports, Buffer, Date, URL, process, require: (name) => {
|
|
43
|
+
if (name === 'node:fs')
|
|
44
|
+
return syncFs;
|
|
45
|
+
if (name === 'node:fs/promises')
|
|
46
|
+
return { ...fs, ...overrides };
|
|
47
|
+
if (name === 'node:crypto')
|
|
48
|
+
return crypto;
|
|
49
|
+
if (name === 'node:path')
|
|
50
|
+
return path;
|
|
51
|
+
if (name === 'node:url')
|
|
52
|
+
return url;
|
|
53
|
+
if (name === 'node:util')
|
|
54
|
+
return util;
|
|
55
|
+
if (name === './bootstrapHostScope.js')
|
|
56
|
+
return { currentBootstrapHostScope };
|
|
57
|
+
if (name === './repositoryKnowledge.js')
|
|
58
|
+
return knowledge;
|
|
59
|
+
if (name === './repositorySourceAuthorization.js')
|
|
60
|
+
return authorization;
|
|
61
|
+
if (name === '@dharma-ai-labs/agent-fabric-contracts')
|
|
62
|
+
return inertSchema
|
|
63
|
+
? { ...contracts, validateContract: overrides.validateContract || (async () => ({ ok: true })) } : contracts;
|
|
64
|
+
if (name === '@dharma-ai-labs/agent-fabric-evidence-reduction')
|
|
65
|
+
return reduction;
|
|
66
|
+
return require(name);
|
|
67
|
+
} }, { timeout: 1000, contextCodeGeneration: { strings: false, wasm: false } });
|
|
68
|
+
return exports;
|
|
69
|
+
}
|
|
70
|
+
test('package capture refuses workspace resolution after original scope closes', async (t) => {
|
|
71
|
+
const f = await fixture(t);
|
|
72
|
+
let resolutions = 0;
|
|
73
|
+
const api = await module({ realpath: async (...args) => { resolutions++; return fs.realpath(...args); } });
|
|
74
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
75
|
+
scope.close();
|
|
76
|
+
await api.inventoryRepositoryPackage(f);
|
|
77
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
78
|
+
assert.equal(resolutions, 0);
|
|
79
|
+
});
|
|
80
|
+
test('package capture stops before metadata after workspace resolution withdraws authority', async (t) => {
|
|
81
|
+
const f = await fixture(t);
|
|
82
|
+
let stats = 0;
|
|
83
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
84
|
+
const api = await module({ realpath: async (...args) => {
|
|
85
|
+
const value = await fs.realpath(...args);
|
|
86
|
+
scope.close();
|
|
87
|
+
return value;
|
|
88
|
+
}, lstat: async (...args) => { stats++; return fs.lstat(...args); } });
|
|
89
|
+
await api.inventoryRepositoryPackage(f);
|
|
90
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
91
|
+
assert.equal(stats, 0);
|
|
92
|
+
});
|
|
93
|
+
test('package capture closes its directory after withdrawal without reading another entry', async (t) => {
|
|
94
|
+
const f = await fixture(t);
|
|
95
|
+
let reads = 0, closes = 0, opens = 0;
|
|
96
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
97
|
+
const api = await module({ opendir: async (...args) => {
|
|
98
|
+
const directory = await fs.opendir(...args), read = directory.read.bind(directory), close = directory.close.bind(directory);
|
|
99
|
+
const controlled = { read: async () => { reads++; const value = await read(); scope.close(); return value; },
|
|
100
|
+
close: async () => { closes++; return close(); },
|
|
101
|
+
async *[Symbol.asyncIterator]() {
|
|
102
|
+
try {
|
|
103
|
+
for (;;) {
|
|
104
|
+
const entry = await controlled.read();
|
|
105
|
+
if (!entry)
|
|
106
|
+
break;
|
|
107
|
+
yield entry;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
await controlled.close();
|
|
112
|
+
}
|
|
113
|
+
} };
|
|
114
|
+
return controlled;
|
|
115
|
+
}, open: async (...args) => { opens++; return fs.open(...args); } });
|
|
116
|
+
await api.inventoryRepositoryPackage(f);
|
|
117
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
118
|
+
assert.equal(reads, 1);
|
|
119
|
+
assert.equal(closes, 1);
|
|
120
|
+
assert.equal(opens, 0);
|
|
121
|
+
});
|
|
122
|
+
test('package capture closes an acquired file after withdrawal without reading it', async (t) => {
|
|
123
|
+
const f = await fixture(t);
|
|
124
|
+
let reads = 0, closes = 0;
|
|
125
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
126
|
+
const api = await module({ open: async (...args) => {
|
|
127
|
+
const handle = await fs.open(...args), read = handle.read.bind(handle), close = handle.close.bind(handle);
|
|
128
|
+
handle.read = ((...values) => { reads++; return Reflect.apply(read, handle, values); });
|
|
129
|
+
handle.close = async () => { closes++; return close(); };
|
|
130
|
+
scope.close();
|
|
131
|
+
return handle;
|
|
132
|
+
} });
|
|
133
|
+
await api.inventoryRepositoryPackage(f);
|
|
134
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
135
|
+
assert.equal(reads, 0);
|
|
136
|
+
assert.equal(closes, 1);
|
|
137
|
+
});
|
|
138
|
+
test('package capture does not convert withdrawal during file read into an unavailable exclusion', async (t) => {
|
|
139
|
+
const f = await fixture(t);
|
|
140
|
+
let reads = 0, closes = 0;
|
|
141
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
142
|
+
const api = await module({ open: async (...args) => {
|
|
143
|
+
const handle = await fs.open(...args), read = handle.read.bind(handle), close = handle.close.bind(handle);
|
|
144
|
+
handle.read = (async (...values) => { reads++; const value = await Reflect.apply(read, handle, values); scope.close(); return value; });
|
|
145
|
+
handle.close = async () => { closes++; return close(); };
|
|
146
|
+
return handle;
|
|
147
|
+
} });
|
|
148
|
+
await api.inventoryRepositoryPackage(f);
|
|
149
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
150
|
+
assert.equal(reads, 1);
|
|
151
|
+
assert.equal(closes, 1);
|
|
152
|
+
});
|
|
153
|
+
test('package capture freezes caller scope and clock before filesystem inspection yields', async (t) => {
|
|
154
|
+
const f = await fixture(t), expected = f.now.toISOString();
|
|
155
|
+
const api = await module({ realpath: async (...args) => {
|
|
156
|
+
const value = await fs.realpath(...args);
|
|
157
|
+
f.organizationId = 'org_foreign';
|
|
158
|
+
f.now.setTime(0);
|
|
159
|
+
return value;
|
|
160
|
+
} });
|
|
161
|
+
const actual = await runCodexBootstrapHost(host(f.workspace), () => api.inventoryRepositoryPackage(f));
|
|
162
|
+
assert.equal(actual.manifest.organizationId, 'org_demo');
|
|
163
|
+
assert.equal(actual.capturedAt, expected);
|
|
164
|
+
assert.equal(actual.manifest.skills.length, 1);
|
|
165
|
+
assert.equal(actual.manifest.skills[0].availability, 'available');
|
|
166
|
+
});
|
|
167
|
+
test('package capture refuses caller getters before filesystem work', async (t) => {
|
|
168
|
+
const f = await fixture(t), workspace = f.workspace;
|
|
169
|
+
let getters = 0, resolutions = 0;
|
|
170
|
+
Object.defineProperty(f, 'workspace', { get: () => { getters++; throw new Error('private input canary'); } });
|
|
171
|
+
const api = await module({ realpath: async (...args) => { resolutions++; return fs.realpath(...args); } });
|
|
172
|
+
await assert.rejects(runCodexBootstrapHost(host(workspace), () => api.inventoryRepositoryPackage(f)), { message: 'repository_package_input_invalid' });
|
|
173
|
+
assert.equal(getters, 0);
|
|
174
|
+
assert.equal(resolutions, 0);
|
|
175
|
+
});
|
|
176
|
+
test('package capture refuses native error accessors without disclosing diagnostics', async (t) => {
|
|
177
|
+
const f = await fixture(t);
|
|
178
|
+
let getters = 0;
|
|
179
|
+
const api = await module({ realpath: async () => {
|
|
180
|
+
throw Object.defineProperty(new Error('private native canary'), 'code', {
|
|
181
|
+
get: () => { getters++; throw new Error('private getter canary'); }
|
|
182
|
+
});
|
|
183
|
+
} });
|
|
184
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), () => api.inventoryRepositoryPackage(f)), { message: 'repository_package_storage_unavailable' });
|
|
185
|
+
assert.equal(getters, 0);
|
|
186
|
+
});
|
|
187
|
+
test('package capture freezes input before asynchronous owner revalidation', async (t) => {
|
|
188
|
+
const f = await fixture(t), expected = f.now.toISOString(), api = await module();
|
|
189
|
+
let armed = false;
|
|
190
|
+
const actual = await runCodexBootstrapHost({ ...host(f.workspace), current: async () => {
|
|
191
|
+
if (armed) {
|
|
192
|
+
f.organizationId = 'org_foreign';
|
|
193
|
+
f.now.setTime(0);
|
|
194
|
+
}
|
|
195
|
+
return true;
|
|
196
|
+
} }, async () => { armed = true; return api.inventoryRepositoryPackage(f); });
|
|
197
|
+
assert.equal(actual.manifest.organizationId, 'org_demo');
|
|
198
|
+
assert.equal(actual.capturedAt, expected);
|
|
199
|
+
});
|
|
200
|
+
test('package capture closes a directory acquired during withdrawal without its first read', async (t) => {
|
|
201
|
+
const f = await fixture(t);
|
|
202
|
+
let reads = 0, closes = 0;
|
|
203
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
204
|
+
const api = await module({ opendir: async (...args) => {
|
|
205
|
+
const directory = await fs.opendir(...args), read = directory.read.bind(directory), close = directory.close.bind(directory);
|
|
206
|
+
scope.close();
|
|
207
|
+
return { read: async () => { reads++; return read(); }, close: async () => { closes++; return close(); } };
|
|
208
|
+
} });
|
|
209
|
+
await api.inventoryRepositoryPackage(f);
|
|
210
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
211
|
+
assert.equal(reads, 0);
|
|
212
|
+
assert.equal(closes, 1);
|
|
213
|
+
});
|
|
214
|
+
test('package capture rejects a nested observation getter without executing it', async (t) => {
|
|
215
|
+
const f = await fixture(t);
|
|
216
|
+
let getters = 0;
|
|
217
|
+
const api = await module(), observation = Object.defineProperty({}, 'sourcePath', {
|
|
218
|
+
get: () => { getters++; throw new Error('private nested canary'); }
|
|
219
|
+
});
|
|
220
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), () => api.inventoryRepositoryPackage({ ...f, observations: [observation] })), { message: 'repository_package_input_invalid' });
|
|
221
|
+
assert.equal(getters, 0);
|
|
222
|
+
});
|
|
223
|
+
test('package capture reports uncertain owned-handle close without native diagnostics', async (t) => {
|
|
224
|
+
const f = await fixture(t);
|
|
225
|
+
let closes = 0;
|
|
226
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
227
|
+
const api = await module({ open: async (...args) => {
|
|
228
|
+
const handle = await fs.open(...args), close = handle.close.bind(handle);
|
|
229
|
+
handle.close = async () => { closes++; await close(); throw new Error('private close canary'); };
|
|
230
|
+
return handle;
|
|
231
|
+
} });
|
|
232
|
+
await api.inventoryRepositoryPackage(f);
|
|
233
|
+
}), { message: 'repository_package_cleanup_unconfirmed' });
|
|
234
|
+
assert.equal(closes, 1);
|
|
235
|
+
});
|
|
236
|
+
test('actual compiled package capture retains governed documents, knowledge and authorized uncommitted reports', async (t) => {
|
|
237
|
+
const f = await fixture(t), id = (n) => `${String(n).padStart(8, '0')}-1111-4111-8111-111111111111`;
|
|
238
|
+
const policy = { action: 'authorize', confirmed: true, requestId: id(5), repositoryBindingId: id(6), expectedRevision: 0,
|
|
239
|
+
allowedContentClasses: ['approved_outputs', 'repository_content', 'repository_skills'],
|
|
240
|
+
approvedRepositoryPaths: ['README.md'], approvedOutputFolders: ['output/approved'], automaticValidatedPublication: true,
|
|
241
|
+
retentionDays: 30, maximumFileBytes: 262144, maximumSnapshotBytes: 4194304, maximumDailyUploadBytes: 8388608, expiresAt: null };
|
|
242
|
+
const sourceAuthorization = { schema: 'dharma.repository-source-authorization/v1', organizationId: f.organizationId,
|
|
243
|
+
workspaceId: id(7), repositoryBindingId: id(6), repositoryAgentId: id(8), revision: 1, generationId: id(9),
|
|
244
|
+
receiptId: `repo_consent_${id(9)}`, policyRevision: `repository-source-${id(9)}`,
|
|
245
|
+
confirmedAt: '2026-09-18T08:00:00.000Z',
|
|
246
|
+
policyHash: `sha256:${crypto.createHash('sha256').update(contracts.canonicalize(policy)).digest('hex')}`, policy };
|
|
247
|
+
const input = { ...f, workspaceId: id(7), repositoryBindingId: id(6), repositoryAgentId: id(8), sourceAuthorization };
|
|
248
|
+
const skill = path.join(f.workspace, '.agents/skills/dharma-agent-fabric');
|
|
249
|
+
await fs.mkdir(skill, { recursive: true });
|
|
250
|
+
await fs.writeFile(path.join(skill, '.dharma-agent-fabric.json'), JSON.stringify({ managedBy: 'dharma-agent-fabric', workspaceId: input.workspaceId }));
|
|
251
|
+
await knowledge.initializeRepositoryKnowledge(input);
|
|
252
|
+
await fs.writeFile(path.join(f.workspace, 'README.md'), '# Logical job\nOne accepted operation.');
|
|
253
|
+
await fs.mkdir(path.join(f.workspace, 'output/approved'), { recursive: true });
|
|
254
|
+
await fs.writeFile(path.join(f.workspace, 'output/approved/report.md'), 'The retry preserved its logical job identifier.');
|
|
255
|
+
await fs.writeFile(path.join(f.workspace, 'unapproved.md'), 'Excluded private fixture.');
|
|
256
|
+
const baseline = await inventoryRepositoryPackage(input);
|
|
257
|
+
const actual = await runCodexBootstrapHost(host(f.workspace), () => inventoryRepositoryPackage(input));
|
|
258
|
+
assert.equal(serializeRepositoryPackageSnapshot(actual), serializeRepositoryPackageSnapshot(baseline));
|
|
259
|
+
assert.equal(actual.manifest.schema, 'dharma.repository-package/v2');
|
|
260
|
+
assert.ok(actual.manifest.files.some(file => file.role === 'knowledge'));
|
|
261
|
+
assert.ok(actual.manifest.files.some(file => file.path === 'output/approved/report.md'));
|
|
262
|
+
assert.ok(actual.manifest.files.every(file => file.path !== 'unapproved.md'));
|
|
263
|
+
});
|
|
264
|
+
const generated = '.agents/skills/dharma-agent-fabric';
|
|
265
|
+
const snapshots = '.dharma/repository-source/snapshots';
|
|
266
|
+
async function writeFixture(t) {
|
|
267
|
+
const f = await fixture(t), snapshot = await inventoryRepositoryPackage(f);
|
|
268
|
+
return { workspace: f.workspace, snapshot };
|
|
269
|
+
}
|
|
270
|
+
function creating(args, prefix) {
|
|
271
|
+
return !!(Number(args[1]) & syncFs.constants.O_CREAT) && path.basename(String(args[0])).startsWith(prefix);
|
|
272
|
+
}
|
|
273
|
+
test('package writer snapshots caller fields before root resolution yields', async (t) => {
|
|
274
|
+
const f = await writeFixture(t), expected = f.snapshot.manifest.snapshotHash;
|
|
275
|
+
let mutated = false;
|
|
276
|
+
const api = await module({ realpath: async (...args) => {
|
|
277
|
+
const value = await fs.realpath(...args);
|
|
278
|
+
if (!mutated) {
|
|
279
|
+
mutated = true;
|
|
280
|
+
f.snapshot.manifest.organizationId = 'org_foreign';
|
|
281
|
+
}
|
|
282
|
+
return value;
|
|
283
|
+
} }, true);
|
|
284
|
+
const actual = await runCodexBootstrapHost(host(f.workspace), () => api.writeRepositoryPackageSnapshot(f));
|
|
285
|
+
assert.equal(actual.snapshotHash, expected);
|
|
286
|
+
assert.equal(actual.disposition, 'local_bootstrap_inventory');
|
|
287
|
+
assert.equal(JSON.parse(await fs.readFile(path.join(f.workspace, generated, 'MANIFEST.json'), 'utf8')).organizationId, 'org_demo');
|
|
288
|
+
});
|
|
289
|
+
test('package writer refuses caller snapshot accessors before filesystem inspection', async (t) => {
|
|
290
|
+
const f = await writeFixture(t);
|
|
291
|
+
let getters = 0, resolutions = 0;
|
|
292
|
+
Object.defineProperty(f.snapshot, 'manifest', { get: () => { getters++; throw new Error('private writer input canary'); } });
|
|
293
|
+
const api = await module({ realpath: async (...args) => { resolutions++; return fs.realpath(...args); } }, true);
|
|
294
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), () => api.writeRepositoryPackageSnapshot(f)), { message: 'repository_package_input_invalid' });
|
|
295
|
+
assert.equal(getters, 0);
|
|
296
|
+
assert.equal(resolutions, 0);
|
|
297
|
+
});
|
|
298
|
+
test('package writer closes acquired CAS staging after withdrawal without writing or deleting it', async (t) => {
|
|
299
|
+
const f = await writeFixture(t);
|
|
300
|
+
let writes = 0, closes = 0, unlinks = 0;
|
|
301
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
302
|
+
const api = await module({ open: async (...args) => {
|
|
303
|
+
const handle = await fs.open(...args);
|
|
304
|
+
if (!creating(args, '.snapshot-'))
|
|
305
|
+
return handle;
|
|
306
|
+
const write = handle.writeFile.bind(handle), close = handle.close.bind(handle);
|
|
307
|
+
handle.writeFile = async (...values) => { writes++; return write(...values); };
|
|
308
|
+
handle.close = async () => { closes++; return close(); };
|
|
309
|
+
scope.close();
|
|
310
|
+
return handle;
|
|
311
|
+
}, unlink: async (...args) => { unlinks++; return fs.unlink(...args); } }, true);
|
|
312
|
+
await api.writeRepositoryPackageSnapshot(f);
|
|
313
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
314
|
+
assert.equal(writes, 0);
|
|
315
|
+
assert.equal(closes, 1);
|
|
316
|
+
assert.equal(unlinks, 0);
|
|
317
|
+
assert.equal((await fs.readdir(path.join(f.workspace, snapshots))).filter(name => name.startsWith('.snapshot-')).length, 1);
|
|
318
|
+
});
|
|
319
|
+
test('package writer retains partial CAS staging and stops sync/publication after write withdrawal', async (t) => {
|
|
320
|
+
const f = await writeFixture(t);
|
|
321
|
+
let writes = 0, syncs = 0, closes = 0, links = 0, unlinks = 0;
|
|
322
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
323
|
+
const api = await module({ open: async (...args) => {
|
|
324
|
+
const handle = await fs.open(...args);
|
|
325
|
+
if (!creating(args, '.snapshot-'))
|
|
326
|
+
return handle;
|
|
327
|
+
const write = handle.writeFile.bind(handle), sync = handle.sync.bind(handle), close = handle.close.bind(handle);
|
|
328
|
+
handle.writeFile = async (...values) => { writes++; const result = await write(...values); scope.close(); return result; };
|
|
329
|
+
handle.sync = async () => { syncs++; return sync(); };
|
|
330
|
+
handle.close = async () => { closes++; return close(); };
|
|
331
|
+
return handle;
|
|
332
|
+
}, link: async (...args) => { links++; return fs.link(...args); },
|
|
333
|
+
unlink: async (...args) => { unlinks++; return fs.unlink(...args); } }, true);
|
|
334
|
+
await api.writeRepositoryPackageSnapshot(f);
|
|
335
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
336
|
+
assert.equal(writes, 1);
|
|
337
|
+
assert.equal(syncs, 0);
|
|
338
|
+
assert.equal(closes, 1);
|
|
339
|
+
assert.equal(links, 0);
|
|
340
|
+
assert.equal(unlinks, 0);
|
|
341
|
+
});
|
|
342
|
+
for (const scoped of [true, false])
|
|
343
|
+
test(`package writer preserves an unowned CAS staging collision (${scoped ? 'scoped' : 'legacy'})`, async (t) => {
|
|
344
|
+
const f = await writeFixture(t);
|
|
345
|
+
let foreign = '', unlinks = 0;
|
|
346
|
+
const api = await module({ open: async (...args) => {
|
|
347
|
+
if (!creating(args, '.snapshot-'))
|
|
348
|
+
return fs.open(...args);
|
|
349
|
+
foreign = String(args[0]);
|
|
350
|
+
await fs.writeFile(foreign, 'foreign staging');
|
|
351
|
+
throw Object.assign(new Error('private exclusive-create canary'), { code: 'EEXIST' });
|
|
352
|
+
}, unlink: async (...args) => { unlinks++; return fs.unlink(...args); } }, true);
|
|
353
|
+
await assert.rejects(scoped ? runCodexBootstrapHost(host(f.workspace), () => api.writeRepositoryPackageSnapshot(f)) : api.writeRepositoryPackageSnapshot(f));
|
|
354
|
+
assert.equal(unlinks, 0);
|
|
355
|
+
assert.equal(await fs.readFile(foreign, 'utf8'), 'foreign staging');
|
|
356
|
+
});
|
|
357
|
+
test('package writer preserves a published CAS object and staged evidence after link withdrawal', async (t) => {
|
|
358
|
+
const f = await writeFixture(t);
|
|
359
|
+
let links = 0, unlinks = 0;
|
|
360
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
361
|
+
const api = await module({ link: async (...args) => {
|
|
362
|
+
links++;
|
|
363
|
+
await fs.link(...args);
|
|
364
|
+
scope.close();
|
|
365
|
+
}, unlink: async (...args) => { unlinks++; return fs.unlink(...args); } }, true);
|
|
366
|
+
await api.writeRepositoryPackageSnapshot(f);
|
|
367
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
368
|
+
assert.equal(links, 1);
|
|
369
|
+
assert.equal(unlinks, 0);
|
|
370
|
+
const names = await fs.readdir(path.join(f.workspace, snapshots));
|
|
371
|
+
assert.equal(names.filter(name => name.startsWith('.snapshot-')).length, 1);
|
|
372
|
+
assert.equal(names.filter(name => name.endsWith('.json')).length, 1);
|
|
373
|
+
});
|
|
374
|
+
test('package writer settles its exact acquired copy lock after link admission withdraws', async (t) => {
|
|
375
|
+
const f = await writeFixture(t);
|
|
376
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
377
|
+
const api = await module({ link: async (...args) => {
|
|
378
|
+
await fs.link(...args);
|
|
379
|
+
if (path.basename(String(args[0])).startsWith('.lock-'))
|
|
380
|
+
scope.close();
|
|
381
|
+
} }, true);
|
|
382
|
+
await api.writeRepositoryPackageSnapshot(f);
|
|
383
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
384
|
+
const names = await fs.readdir(path.join(f.workspace, generated));
|
|
385
|
+
assert.ok(!names.includes('COPY-LOCK.json'));
|
|
386
|
+
assert.ok(names.every(name => !name.startsWith('.lock-')));
|
|
387
|
+
assert.ok(!names.includes('COPY-JOURNAL.json'));
|
|
388
|
+
});
|
|
389
|
+
test('package writer retains interrupted journal, releases its own lock and recovers the actual managed-copy path', async (t) => {
|
|
390
|
+
const f = await writeFixture(t), api = await module({}, true);
|
|
391
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => api.writeRepositoryPackageSnapshot({ ...f,
|
|
392
|
+
onCopyCheckpoint: (point) => { if (point === 'journal_prepared')
|
|
393
|
+
scope.close(); } })), { message: 'codex_setup_host_scope_unavailable' });
|
|
394
|
+
const journal = path.join(f.workspace, generated, 'COPY-JOURNAL.json'), bytes = await fs.readFile(journal);
|
|
395
|
+
assert.equal(JSON.parse(bytes.toString()).desired.snapshotHash, f.snapshot.manifest.snapshotHash);
|
|
396
|
+
await assert.rejects(fs.stat(path.join(f.workspace, generated, 'COPY-LOCK.json')), { code: 'ENOENT' });
|
|
397
|
+
await assert.rejects(fs.stat(path.join(f.workspace, generated, 'skills/source/.agents/skills/example/SKILL.md')), { code: 'ENOENT' });
|
|
398
|
+
const actual = await api.writeRepositoryPackageSnapshot(f);
|
|
399
|
+
assert.equal(actual.disposition, 'local_bootstrap_inventory');
|
|
400
|
+
assert.equal(await fs.readFile(path.join(f.workspace, generated, 'skills/source/.agents/skills/example/SKILL.md'), 'utf8'), await fs.readFile(path.join(f.workspace, '.agents/skills/example/SKILL.md'), 'utf8'));
|
|
401
|
+
await assert.rejects(fs.stat(journal), { code: 'ENOENT' });
|
|
402
|
+
});
|
|
403
|
+
test('package writer preserves foreign replacement of its lock during withdrawal', async (t) => {
|
|
404
|
+
const f = await writeFixture(t), api = await module({}, true);
|
|
405
|
+
let classification = '';
|
|
406
|
+
const lock = path.join(f.workspace, generated, 'COPY-LOCK.json');
|
|
407
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
408
|
+
try {
|
|
409
|
+
await api.writeRepositoryPackageSnapshot({ ...f, onCopyCheckpoint: async (point) => {
|
|
410
|
+
if (point !== 'journal_prepared')
|
|
411
|
+
return;
|
|
412
|
+
await fs.unlink(lock);
|
|
413
|
+
await fs.writeFile(lock, 'foreign lock');
|
|
414
|
+
scope.close();
|
|
415
|
+
} });
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
classification = error.message;
|
|
419
|
+
throw error;
|
|
420
|
+
}
|
|
421
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
422
|
+
assert.equal(classification, 'repository_package_cleanup_unconfirmed');
|
|
423
|
+
assert.equal(await fs.readFile(lock, 'utf8'), 'foreign lock');
|
|
424
|
+
});
|
|
425
|
+
test('actual compiled scoped writer preserves normal managed-copy and manifest behavior', async (t) => {
|
|
426
|
+
const f = await writeFixture(t);
|
|
427
|
+
const actual = await runCodexBootstrapHost(host(f.workspace), () => writeRepositoryPackageSnapshot(f));
|
|
428
|
+
assert.equal(actual.disposition, 'local_bootstrap_inventory');
|
|
429
|
+
assert.equal(actual.snapshotHash, f.snapshot.manifest.snapshotHash);
|
|
430
|
+
assert.equal(await fs.readFile(path.join(f.workspace, generated, 'MANIFEST.json'), 'utf8'), `${contracts.canonicalize(f.snapshot.manifest)}\n`);
|
|
431
|
+
assert.equal(await fs.readFile(path.join(f.workspace, generated, 'skills/source/.agents/skills/example/SKILL.md'), 'utf8'), await fs.readFile(path.join(f.workspace, '.agents/skills/example/SKILL.md'), 'utf8'));
|
|
432
|
+
await assert.rejects(fs.stat(path.join(f.workspace, generated, 'COPY-LOCK.json')), { code: 'ENOENT' });
|
|
433
|
+
});
|
|
434
|
+
test('package writer refuses foreign CAS staging replacement before publishing it', async (t) => {
|
|
435
|
+
const f = await writeFixture(t);
|
|
436
|
+
let foreign = '', links = 0;
|
|
437
|
+
const api = await module({ open: async (...args) => {
|
|
438
|
+
const handle = await fs.open(...args);
|
|
439
|
+
if (!creating(args, '.snapshot-'))
|
|
440
|
+
return handle;
|
|
441
|
+
const close = handle.close.bind(handle);
|
|
442
|
+
handle.close = async () => { await close(); foreign = String(args[0]); await fs.unlink(foreign); await fs.writeFile(foreign, 'foreign staging'); };
|
|
443
|
+
return handle;
|
|
444
|
+
}, link: async (...args) => { links++; return fs.link(...args); } }, true);
|
|
445
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), () => api.writeRepositoryPackageSnapshot(f)));
|
|
446
|
+
assert.equal(links, 0);
|
|
447
|
+
assert.equal(await fs.readFile(foreign, 'utf8'), 'foreign staging');
|
|
448
|
+
assert.equal((await fs.readdir(path.join(f.workspace, snapshots))).filter(name => name.endsWith('.json')).length, 0);
|
|
449
|
+
});
|
|
450
|
+
test('package writer refuses same-inode CAS staging edits before publishing them', async (t) => {
|
|
451
|
+
const f = await writeFixture(t);
|
|
452
|
+
let edited = '', links = 0;
|
|
453
|
+
const api = await module({ open: async (...args) => {
|
|
454
|
+
const handle = await fs.open(...args);
|
|
455
|
+
if (!creating(args, '.snapshot-'))
|
|
456
|
+
return handle;
|
|
457
|
+
const close = handle.close.bind(handle);
|
|
458
|
+
handle.close = async () => { await close(); edited = String(args[0]); await fs.writeFile(edited, 'intervening edit'); };
|
|
459
|
+
return handle;
|
|
460
|
+
}, link: async (...args) => { links++; return fs.link(...args); } }, true);
|
|
461
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), () => api.writeRepositoryPackageSnapshot(f)));
|
|
462
|
+
assert.equal(links, 0);
|
|
463
|
+
assert.equal(await fs.readFile(edited, 'utf8'), 'intervening edit');
|
|
464
|
+
});
|
|
465
|
+
test('package writer preserves foreign metadata staging before journal rename', async (t) => {
|
|
466
|
+
const f = await writeFixture(t);
|
|
467
|
+
let foreign = '', renames = 0;
|
|
468
|
+
const api = await module({ open: async (...args) => {
|
|
469
|
+
const handle = await fs.open(...args);
|
|
470
|
+
if (!creating(args, '.metadata-'))
|
|
471
|
+
return handle;
|
|
472
|
+
const close = handle.close.bind(handle);
|
|
473
|
+
handle.close = async () => { await close(); foreign = String(args[0]); await fs.unlink(foreign); await fs.writeFile(foreign, 'foreign metadata'); };
|
|
474
|
+
return handle;
|
|
475
|
+
}, rename: async (...args) => { renames++; return fs.rename(...args); } }, true);
|
|
476
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), () => api.writeRepositoryPackageSnapshot(f)));
|
|
477
|
+
assert.equal(renames, 0);
|
|
478
|
+
assert.equal(await fs.readFile(foreign, 'utf8'), 'foreign metadata');
|
|
479
|
+
await assert.rejects(fs.stat(path.join(f.workspace, generated, 'COPY-JOURNAL.json')), { code: 'ENOENT' });
|
|
480
|
+
});
|
|
481
|
+
test('package writer refuses foreign lock candidate before acquiring it or starting journal work', async (t) => {
|
|
482
|
+
const f = await writeFixture(t);
|
|
483
|
+
let foreign = '', lockLinks = 0;
|
|
484
|
+
const api = await module({ open: async (...args) => {
|
|
485
|
+
const handle = await fs.open(...args);
|
|
486
|
+
if (!creating(args, '.lock-'))
|
|
487
|
+
return handle;
|
|
488
|
+
const close = handle.close.bind(handle);
|
|
489
|
+
handle.close = async () => { await close(); foreign = String(args[0]); await fs.unlink(foreign); await fs.writeFile(foreign, 'foreign lock candidate'); };
|
|
490
|
+
return handle;
|
|
491
|
+
}, link: async (...args) => {
|
|
492
|
+
if (path.basename(String(args[0])).startsWith('.lock-'))
|
|
493
|
+
lockLinks++;
|
|
494
|
+
return fs.link(...args);
|
|
495
|
+
} }, true);
|
|
496
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), () => api.writeRepositoryPackageSnapshot(f)));
|
|
497
|
+
assert.equal(lockLinks, 0);
|
|
498
|
+
assert.equal(await fs.readFile(foreign, 'utf8'), 'foreign lock candidate');
|
|
499
|
+
await assert.rejects(fs.stat(path.join(f.workspace, generated, 'COPY-JOURNAL.json')), { code: 'ENOENT' });
|
|
500
|
+
});
|
|
501
|
+
test('package writer retains a published journal after rename withdrawal without installing a copy', async (t) => {
|
|
502
|
+
const f = await writeFixture(t), workspace = await fs.realpath(f.workspace);
|
|
503
|
+
const journal = path.join(workspace, generated, 'COPY-JOURNAL.json');
|
|
504
|
+
let withdrawals = 0;
|
|
505
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
506
|
+
const api = await module({ rename: async (...args) => {
|
|
507
|
+
await fs.rename(...args);
|
|
508
|
+
if (String(args[1]) === journal) {
|
|
509
|
+
withdrawals++;
|
|
510
|
+
scope.close();
|
|
511
|
+
}
|
|
512
|
+
} }, true);
|
|
513
|
+
await api.writeRepositoryPackageSnapshot(f);
|
|
514
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
515
|
+
assert.equal(withdrawals, 1);
|
|
516
|
+
assert.equal(JSON.parse(await fs.readFile(journal, 'utf8')).desired.snapshotHash, f.snapshot.manifest.snapshotHash);
|
|
517
|
+
await assert.rejects(fs.stat(path.join(f.workspace, generated, 'COPY-LOCK.json')), { code: 'ENOENT' });
|
|
518
|
+
await assert.rejects(fs.stat(path.join(f.workspace, generated, 'skills/source/.agents/skills/example/SKILL.md')), { code: 'ENOENT' });
|
|
519
|
+
});
|
|
520
|
+
test('package writer preserves installed copy and journal after link withdrawal, then recovers without replacing the source', async (t) => {
|
|
521
|
+
const f = await writeFixture(t);
|
|
522
|
+
let api;
|
|
523
|
+
await assert.rejects(runCodexBootstrapHost(host(f.workspace), async ({ scope }) => {
|
|
524
|
+
api = await module({ link: async (...args) => {
|
|
525
|
+
await fs.link(...args);
|
|
526
|
+
if (String(args[0]).replaceAll('\\', '/').includes('/.copy-transactions/'))
|
|
527
|
+
scope.close();
|
|
528
|
+
} }, true);
|
|
529
|
+
await api.writeRepositoryPackageSnapshot(f);
|
|
530
|
+
}), { message: 'codex_setup_host_scope_unavailable' });
|
|
531
|
+
const target = path.join(f.workspace, generated, 'skills/source/.agents/skills/example/SKILL.md');
|
|
532
|
+
const before = await fs.stat(target, { bigint: true }), bytes = await fs.readFile(target);
|
|
533
|
+
await assert.rejects(fs.stat(path.join(f.workspace, generated, 'COPY-INDEX.json')), { code: 'ENOENT' });
|
|
534
|
+
await assert.rejects(fs.stat(path.join(f.workspace, generated, 'COPY-LOCK.json')), { code: 'ENOENT' });
|
|
535
|
+
const actual = await api.writeRepositoryPackageSnapshot(f);
|
|
536
|
+
assert.equal(actual.disposition, 'local_bootstrap_inventory');
|
|
537
|
+
assert.equal((await fs.stat(target, { bigint: true })).ino, before.ino);
|
|
538
|
+
assert.deepEqual(await fs.readFile(target), bytes);
|
|
539
|
+
await assert.rejects(fs.stat(path.join(f.workspace, generated, 'COPY-JOURNAL.json')), { code: 'ENOENT' });
|
|
540
|
+
});
|
|
541
|
+
test('queued package writer retains its closed original scope instead of falling back to legacy publication', async (t) => {
|
|
542
|
+
const f = await writeFixture(t);
|
|
543
|
+
let resume, paused, resolved;
|
|
544
|
+
const pause = new Promise(resolve => { paused = resolve; }), release = new Promise(resolve => { resume = resolve; });
|
|
545
|
+
const resolution = new Promise(resolve => { resolved = resolve; });
|
|
546
|
+
let secondScope, validations = 0;
|
|
547
|
+
const api = await module({ realpath: async (...args) => {
|
|
548
|
+
const value = await fs.realpath(...args);
|
|
549
|
+
if (currentBootstrapHostScope() === secondScope && secondScope)
|
|
550
|
+
resolved();
|
|
551
|
+
return value;
|
|
552
|
+
}, validateContract: async () => {
|
|
553
|
+
if (currentBootstrapHostScope() === secondScope && secondScope)
|
|
554
|
+
validations++;
|
|
555
|
+
return { ok: true };
|
|
556
|
+
} }, true);
|
|
557
|
+
const first = api.writeRepositoryPackageSnapshot({ ...f, onCopyCheckpoint: async (point) => {
|
|
558
|
+
if (point === 'journal_prepared') {
|
|
559
|
+
paused();
|
|
560
|
+
await release;
|
|
561
|
+
}
|
|
562
|
+
} });
|
|
563
|
+
await pause;
|
|
564
|
+
const second = runCodexBootstrapHost(host(f.workspace), async ({ scope }) => { secondScope = scope; return api.writeRepositoryPackageSnapshot(f); });
|
|
565
|
+
const rejected = assert.rejects(second, { message: 'codex_setup_host_scope_unavailable' });
|
|
566
|
+
try {
|
|
567
|
+
await resolution;
|
|
568
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
569
|
+
secondScope.close();
|
|
570
|
+
}
|
|
571
|
+
finally {
|
|
572
|
+
resume();
|
|
573
|
+
}
|
|
574
|
+
await first;
|
|
575
|
+
await rejected;
|
|
576
|
+
assert.equal(validations, 0);
|
|
577
|
+
});
|
|
578
|
+
//# sourceMappingURL=repositoryPackageScope.test.js.map
|