Files
Genarrative/apps/ai-game-creator-shell/scripts/agent-runtime-real-e2e/suites/self-test.mjs
T
kdletters 02fff8f308 修复AGC无人值守游戏生成阻断
普通Web工作台默认使用单Supervisor自主生成链路

补齐安全默认返工、结构化诊断与同Run恢复

绑定当前revision、入口摘要和双视口试玩完成凭证

增强Runner跨boot单飞恢复与game-chat来源隔离

新增真实Provider验收入口及确定性回归

同步更新技术方案、开发流程和共享决策
2026-08-14 07:14:25 +08:00

1712 lines
67 KiB
JavaScript

import {
assert,
canonicalJsonValue,
hashJsonValue,
hashValue,
} from '../assertions/core.mjs';
import {
collectToolPlanRepairAuditEvidence,
countExactSecrets,
emptyToolPlanRepairCountsByProtocolErrorKind,
hasSafeToolPlanAuditPayload,
isNonEmptyString,
sumObjectValues,
toolPlanRepairEvidenceHasNoFatalLocalRepair,
} from '../assertions/runtime.mjs';
import { fs, os, path, readFileSync } from '../dependencies.mjs';
import {
isolatedSuiteAppDataProfile,
isolatedSuiteProtectsSourceAppData,
isolatedSuiteUsesSiblingAppData,
sourceAppDataDirectoryEventIsViolation,
} from '../harness/app-data.mjs';
import { parseArguments } from '../harness/config.mjs';
import { safeProcessFailureDiagnostic } from '../harness/process.mjs';
import { requiredAgentIdsForSuite } from '../harness/project.mjs';
import { isIsolatedRunnerSuite } from '../harness/reporting.mjs';
import { agentConversationPath } from '../harness/runtime.mjs';
import {
appRoot,
commandFailureMarker,
commandPassedMarker,
isolatedAgentJoinClaimSchemaVersion,
mainAgentId,
projectSupervisorAgentId,
providerActionBatchSchemaVersion,
repoRoot,
runnerEndpointFileName,
state,
StreamingSecretScanner,
supervisorAutonomousPlayableAppDataSentinelFileName,
supervisorAutonomousPlayableAppDataSentinelSchema,
supervisorAutonomousPlayableLaneDefenseSuite,
supervisorAutonomousPlayableLaneDefenseTask,
supervisorCollaborationContractSchemaVersion,
supervisorCollaborationPolicySchemaVersion,
supervisorCollaborationPolicySnapshotInitialBatchBinding,
supervisorCollaborationPolicySnapshotSchemaVersion,
supervisorGameChatSingleMainPlayableSuite,
supervisorSwarmAutonomousChatSuite,
supervisorSwarmCollaborationPolicyMixedRecoverySuite,
supervisorSwarmFollowupIsolatedReviews,
supervisorSwarmInitialIsolatedReviews,
supervisorSwarmIsolatedReviewGroups,
supervisorSwarmIsolatedReviews,
supervisorSwarmSessionId,
supervisorSwarmStaticIsolatedAutonomousChatSuite,
supervisorSwarmToolPlanHandoffRunnerKillAppDataSentinelFileName,
supervisorSwarmToolPlanHandoffRunnerKillAppDataSentinelSchema,
supervisorSwarmToolPlanHandoffRunnerKillSuite,
toolPlanProtocolAuditSafeFields,
toolPlanProtocolErrorKinds,
toolPlanRepairAuditSafeFields,
} from '../runtime-state.mjs';
import {
buildSupervisorAutonomousPlayablePartialEvidence,
buildSupervisorAutonomousPlayableStdin,
collectPartialSupervisorAutonomousPlayableEvidence,
isSupervisorAutonomousPlayableLaneDefenseSuite,
isSupervisorGameChatSingleMainPlayableSuite,
supervisorAutonomousPlayableMode,
} from './supervisor-autonomous-playable.mjs';
import {
buildSupervisorSwarmEvidence,
collectSupervisorSwarmDynamicPrivateValues,
driftedSupervisorSwarmCollaborationPolicy,
duplicateSupervisorSwarmCollaborationPolicySnapshotBindingCount,
duplicateSupervisorSwarmCollaborationPolicySnapshotCount,
expectedSupervisorSwarmCollaborationPolicy,
inspectSupervisorSwarmCollaborationPolicySnapshot,
inspectSupervisorSwarmCollaborationPolicySnapshotBinding,
inspectSupervisorSwarmRecoveredRepairConfirmationLifecycle,
isSupervisorSwarmSuite,
isSupervisorSwarmToolPlanHandoffRunnerKillSuite,
normalizeSupervisorSwarmToolPlanUpdate,
parseSupervisorSwarmToolPlanHandoffPlan,
registerSupervisorSwarmPrivateOutputValues,
registerSupervisorSwarmPrivateTransportValues,
supervisorSwarmCollaborationPolicyDriftObservationCount,
supervisorSwarmCollaborationPolicySnapshotBinding,
supervisorSwarmEvidenceFieldTemplate,
supervisorSwarmExpectedIsolatedReviewGroups,
supervisorSwarmFinalReplyFaultInjectionAllowed,
supervisorSwarmFinalReplyFaultPrerequisites,
supervisorSwarmFollowupBeforeClaimOrderValid,
supervisorSwarmHostVerificationPassed,
supervisorSwarmInitialBatchBindsPolicySnapshot,
supervisorSwarmIsolatedReviewGroupIndex,
supervisorSwarmIsolatedWriteScopeRoots,
supervisorSwarmMixedIsolatedGroupEntries,
supervisorSwarmObservedJoinClaimForGroups,
supervisorSwarmReadyIsolatedGroupIds,
supervisorSwarmResidualSidecarsEmpty,
supervisorSwarmSeedPrivateValues,
supervisorSwarmToolPlanHandoffProxyNeedsCleanup,
supervisorSwarmToolPlanHandoffSnapshotEvidence,
validateSupervisorSwarmCollaborationPolicySnapshot,
validateSupervisorSwarmCollaborationPolicySnapshotBinding,
} from './supervisor-swarm.mjs';
export async function runAgentRuntimeRealE2eSelfTests() {
const syntheticSourceEndpointLifecycleEvents = [
{ phase: 'created', fileName: runnerEndpointFileName },
{ phase: 'deleted', fileName: Buffer.from(runnerEndpointFileName) },
];
const sourceEndpointAbsentLifecycleGuardValidated =
syntheticSourceEndpointLifecycleEvents.every(({ fileName }) =>
sourceAppDataDirectoryEventIsViolation(
fileName,
'.synthetic-isolated-suite-',
{ exists: false, fingerprint: null },
),
) &&
!sourceAppDataDirectoryEventIsViolation(
runnerEndpointFileName,
'.synthetic-isolated-suite-',
{ exists: true, fingerprint: 'synthetic-endpoint-fingerprint' },
) &&
sourceAppDataDirectoryEventIsViolation(
'.synthetic-isolated-suite-created',
'.synthetic-isolated-suite-',
{ exists: true, fingerprint: 'synthetic-endpoint-fingerprint' },
) &&
!sourceAppDataDirectoryEventIsViolation(
'unrelated-source-config-file.json',
'.synthetic-isolated-suite-',
{ exists: false, fingerprint: null },
);
assert(
sourceEndpointAbsentLifecycleGuardValidated,
'agent-runtime-real-e2e-self-test-source-endpoint-lifecycle-guard-invalid',
);
const previousSuiteForToolPlanHandoff = state.suite;
state.suite = supervisorSwarmToolPlanHandoffRunnerKillSuite;
const toolPlanHandoffProfile = isolatedSuiteAppDataProfile();
const toolPlanHandoffParsedArguments = parseArguments([
'--config-dir',
path.resolve('synthetic-tool-plan-handoff-config'),
'--suite',
supervisorSwarmToolPlanHandoffRunnerKillSuite,
]);
const rootPackage = JSON.parse(
readFileSync(path.join(repoRoot, 'package.json'), 'utf8'),
);
const shellPackage = JSON.parse(
readFileSync(path.join(appRoot, 'package.json'), 'utf8'),
);
const previousSuiteForGameChatPlayable = state.suite;
state.suite = supervisorAutonomousPlayableLaneDefenseSuite;
const professionalPlayableMode = supervisorAutonomousPlayableMode();
const professionalPlayableRequiredAgents = requiredAgentIdsForSuite();
state.suite = supervisorGameChatSingleMainPlayableSuite;
const gameChatPlayableProfile = isolatedSuiteAppDataProfile();
const gameChatPlayableParsedArguments = parseArguments([
'--config-dir',
path.resolve('synthetic-game-chat-playable-config'),
'--suite',
supervisorGameChatSingleMainPlayableSuite,
]);
const gameChatPlayableMode = supervisorAutonomousPlayableMode();
const gameChatPlayableRequiredAgents = requiredAgentIdsForSuite();
const gameChatPlayablePackageCommandsRegistered =
shellPackage.scripts?.[
'agent-runtime:supervisor-game-chat-single-main-playable-real-e2e'
] ===
'node scripts/agent-runtime-real-e2e.mjs --suite supervisor-game-chat-single-main-playable' &&
rootPackage.scripts?.[
'ai-game-creator-shell:agent-runtime:supervisor-game-chat-single-main-playable-real-e2e'
] ===
'npm --prefix apps/ai-game-creator-shell run agent-runtime:supervisor-game-chat-single-main-playable-real-e2e --';
const gameChatPlayableSuiteRegistered =
gameChatPlayableParsedArguments.suite ===
supervisorGameChatSingleMainPlayableSuite &&
isSupervisorGameChatSingleMainPlayableSuite() &&
isSupervisorAutonomousPlayableLaneDefenseSuite() &&
!isSupervisorSwarmSuite() &&
isIsolatedRunnerSuite() &&
isolatedSuiteProtectsSourceAppData() &&
isolatedSuiteUsesSiblingAppData() &&
gameChatPlayableProfile.sentinelName ===
supervisorAutonomousPlayableAppDataSentinelFileName &&
gameChatPlayableProfile.sentinelSchema ===
supervisorAutonomousPlayableAppDataSentinelSchema;
const gameChatPlayableModeValidated =
professionalPlayableMode.gameChatSingleMain === false &&
professionalPlayableMode.rootSource === 'project-supervisor-cli' &&
professionalPlayableMode.evidenceAgentId === projectSupervisorAgentId &&
professionalPlayableMode.scenario ===
'project-supervisor-autonomous-playable-lane-defense' &&
professionalPlayableMode.cliFlags.length === 0 &&
gameChatPlayableMode.gameChatSingleMain === true &&
gameChatPlayableMode.rootSource === 'project-supervisor-game-chat' &&
gameChatPlayableMode.evidenceAgentId === mainAgentId &&
gameChatPlayableMode.scenario ===
'project-supervisor-game-chat-single-main-playable' &&
JSON.stringify(gameChatPlayableMode.cliFlags) ===
JSON.stringify(['--game-chat-smoke']);
const gameChatPlayableRequiredAgentsValidated =
JSON.stringify(professionalPlayableRequiredAgents) ===
JSON.stringify([projectSupervisorAgentId]) &&
JSON.stringify(gameChatPlayableRequiredAgents) ===
JSON.stringify([projectSupervisorAgentId, mainAgentId]);
state.suite = previousSuiteForGameChatPlayable;
assert(
gameChatPlayableSuiteRegistered &&
gameChatPlayablePackageCommandsRegistered &&
gameChatPlayableModeValidated &&
gameChatPlayableRequiredAgentsValidated,
'agent-runtime-real-e2e-self-test-game-chat-playable-suite-invalid',
);
const previousSuiteForAutonomousPlayable = state.suite;
state.suite = supervisorAutonomousPlayableLaneDefenseSuite;
const autonomousPlayableProfile = isolatedSuiteAppDataProfile();
const autonomousPlayableParsedArguments = parseArguments([
'--config-dir',
path.resolve('synthetic-autonomous-playable-config'),
'--suite',
supervisorAutonomousPlayableLaneDefenseSuite,
]);
const autonomousPlayableStdin = buildSupervisorAutonomousPlayableStdin();
const autonomousPlayablePackageCommandsRegistered =
shellPackage.scripts?.[
'agent-runtime:supervisor-autonomous-playable-lane-defense-real-e2e'
] ===
'node scripts/agent-runtime-real-e2e.mjs --suite supervisor-autonomous-playable-lane-defense' &&
rootPackage.scripts?.[
'ai-game-creator-shell:agent-runtime:supervisor-autonomous-playable-lane-defense-real-e2e'
] ===
'npm --prefix apps/ai-game-creator-shell run agent-runtime:supervisor-autonomous-playable-lane-defense-real-e2e --';
const autonomousPlayableSuiteRegistered =
autonomousPlayableParsedArguments.suite ===
supervisorAutonomousPlayableLaneDefenseSuite &&
isSupervisorAutonomousPlayableLaneDefenseSuite() &&
!isSupervisorSwarmSuite() &&
isIsolatedRunnerSuite() &&
isolatedSuiteProtectsSourceAppData() &&
isolatedSuiteUsesSiblingAppData() &&
autonomousPlayableProfile.sentinelName ===
supervisorAutonomousPlayableAppDataSentinelFileName &&
autonomousPlayableProfile.sentinelSchema ===
supervisorAutonomousPlayableAppDataSentinelSchema &&
autonomousPlayableStdin.equals(
Buffer.from(`${supervisorAutonomousPlayableLaneDefenseTask}\n`, 'utf8'),
) &&
autonomousPlayablePackageCommandsRegistered;
const previousInitialRunIdForAutonomousPlayable = state.initialRunId;
const previousProjectRootForAutonomousPlayable = state.projectRoot;
const previousInitialTaskForAutonomousPlayable = state.initialTask;
const previousAutonomousPlayableTurnReport =
state.supervisorAutonomousPlayable.turnReport;
const previousAutonomousPlayablePrivateValues = [
...state.supervisorAutonomousPlayable.privateValues,
];
const previousSupervisorSwarmPrivateValues = [
...state.supervisorSwarm.privateValues,
];
const previousSupervisorSwarmInitialProviderBatch =
state.supervisorSwarm.initialProviderBatch;
const autonomousPlayablePartialCanary = 'private-autonomous-partial-canary';
const syntheticAutonomousPlayableRunId =
'synthetic-autonomous-playable-partial-root';
state.initialRunId = syntheticAutonomousPlayableRunId;
state.supervisorAutonomousPlayable.privateValues = [
...new Set([
...state.supervisorAutonomousPlayable.privateValues,
autonomousPlayablePartialCanary,
]),
];
const syntheticAutonomousPlayablePartialEvidence =
buildSupervisorAutonomousPlayablePartialEvidence(
{
taskSnapshot: {
latest: [
{
agentId: projectSupervisorAgentId,
runId: syntheticAutonomousPlayableRunId,
status: 'running',
phase: 'waiting-for-agent',
task: autonomousPlayablePartialCanary,
},
{
agentId: 'code-prototype',
sessionId: 'synthetic-original-session',
runId: 'synthetic-original-run',
parentAgentId: projectSupervisorAgentId,
parentRunId: syntheticAutonomousPlayableRunId,
delegationId: 'synthetic-original-delivery',
status: 'failed',
phase: 'failed',
},
{
agentId: 'code-prototype',
sessionId: 'synthetic-repair-session',
runId: 'synthetic-repair-run',
parentAgentId: projectSupervisorAgentId,
parentRunId: syntheticAutonomousPlayableRunId,
delegationId: 'synthetic-repair-delivery',
status: 'running',
phase: 'planning',
},
],
},
runtimeStates: [
{
agentId: projectSupervisorAgentId,
runId: syntheticAutonomousPlayableRunId,
status: 'running',
phase: 'waiting-for-agent',
currentTask: autonomousPlayablePartialCanary,
},
{
agentId: 'code-prototype',
runId: 'synthetic-original-run',
parentAgentId: projectSupervisorAgentId,
parentRunId: syntheticAutonomousPlayableRunId,
status: 'failed',
phase: 'failed',
},
{
agentId: 'code-prototype',
runId: 'synthetic-repair-run',
parentAgentId: projectSupervisorAgentId,
parentRunId: syntheticAutonomousPlayableRunId,
status: 'running',
phase: 'waiting-for-provider-retry',
},
],
deliveries: [
{
parentAgentId: projectSupervisorAgentId,
parentRunId: syntheticAutonomousPlayableRunId,
delegationId: 'synthetic-original-delivery',
repairOfDelegationId: null,
targetAgentId: 'code-prototype',
targetSessionId: 'synthetic-original-session',
targetRunId: 'synthetic-original-run',
status: 'ready',
terminalStatus: 'failed',
structuredResult: { contractStatus: 'needs-repair' },
},
{
parentAgentId: projectSupervisorAgentId,
parentRunId: syntheticAutonomousPlayableRunId,
delegationId: 'synthetic-repair-delivery',
repairOfDelegationId: 'synthetic-original-delivery',
targetAgentId: 'code-prototype',
targetSessionId: 'synthetic-repair-session',
targetRunId: 'synthetic-repair-run',
status: 'dispatched',
terminalStatus: null,
},
],
agentDb: [
{
recordType: 'agent.runtime.provider_request.lifecycle',
agentId: 'code-prototype',
runId: 'synthetic-original-run',
requestId: 'synthetic-provider-request',
status: 'started',
},
{
recordType: 'agent.runtime.provider_request.lifecycle',
agentId: 'code-prototype',
runId: 'synthetic-original-run',
requestId: 'synthetic-provider-request',
status: 'failed',
},
{
recordType: 'agent.runtime.provider_request.retry',
agentId: 'code-prototype',
runId: 'synthetic-original-run',
errorKind: 'transport',
},
],
supervisorConversation: [
{
role: 'user',
content: autonomousPlayablePartialCanary,
},
],
professionalConversations: [],
failureEvidenceErrors: {},
},
{
residualSidecars: { providerRetries: 1 },
pendingActionCount: 0,
turnReport: {
outcome: 'incomplete',
parentAgentId: projectSupervisorAgentId,
sessionId: supervisorSwarmSessionId,
parentRunId: syntheticAutonomousPlayableRunId,
runtimeCount: 3,
busyRuntimeCount: 2,
pendingTaskCount: 0,
runningTaskCount: 2,
waitingForConfirmationCount: 0,
waitingForUserInputCount: 0,
reconciliationAgentCount: 0,
},
},
);
const autonomousPlayablePartialEvidenceValidated =
syntheticAutonomousPlayablePartialEvidence.evidenceCompleteness ===
'partial' &&
syntheticAutonomousPlayablePartialEvidence.partialEvidenceCollected ===
true &&
syntheticAutonomousPlayablePartialEvidence.partialPrivacyScanComplete ===
false &&
syntheticAutonomousPlayablePartialEvidence.rootRunObserved === true &&
syntheticAutonomousPlayablePartialEvidence.parentRuntimePhase ===
'waiting-for-agent' &&
syntheticAutonomousPlayablePartialEvidence.childTaskStatusCounts.failed ===
1 &&
syntheticAutonomousPlayablePartialEvidence.childTaskStatusCounts.running ===
1 &&
syntheticAutonomousPlayablePartialEvidence.failedOriginalChildCount === 1 &&
syntheticAutonomousPlayablePartialEvidence.failedRepairChildCount === 0 &&
syntheticAutonomousPlayablePartialEvidence.awaitingRepairCount === 1 &&
syntheticAutonomousPlayablePartialEvidence.repairDeliveryStatusCounts
.dispatched === 1 &&
syntheticAutonomousPlayablePartialEvidence.providerLifecycleFailedCount ===
1 &&
syntheticAutonomousPlayablePartialEvidence.providerRetryAuditCount === 1 &&
syntheticAutonomousPlayablePartialEvidence.providerTransportRetryAuditCount ===
1 &&
syntheticAutonomousPlayablePartialEvidence.providerRetrySidecarCount ===
1 &&
syntheticAutonomousPlayablePartialEvidence.turnReportOutcome ===
'incomplete' &&
syntheticAutonomousPlayablePartialEvidence.turnReportCaptured === true &&
syntheticAutonomousPlayablePartialEvidence.turnReportParentIdentityStable ===
true &&
syntheticAutonomousPlayablePartialEvidence.turnReportPrivateLeakCount ===
0 &&
!JSON.stringify(syntheticAutonomousPlayablePartialEvidence).includes(
autonomousPlayablePartialCanary,
);
const syntheticAutonomousPlayableCollectorRoot = await fs.mkdtemp(
path.join(os.tmpdir(), 'genarrative-autonomous-partial-self-test-'),
);
let syntheticAutonomousPlayableCollectorEvidence;
try {
state.projectRoot = syntheticAutonomousPlayableCollectorRoot;
state.initialTask = {
bytes: Buffer.byteLength(autonomousPlayablePartialCanary, 'utf8'),
sha256: hashValue(autonomousPlayablePartialCanary),
};
state.supervisorSwarm.privateValues = [autonomousPlayablePartialCanary];
state.supervisorSwarm.initialProviderBatch = null;
state.supervisorAutonomousPlayable.turnReport = {
outcome: 'needs-reconciliation',
parentAgentId: projectSupervisorAgentId,
sessionId: supervisorSwarmSessionId,
parentRunId: syntheticAutonomousPlayableRunId,
runtimeCount: 1,
busyRuntimeCount: 0,
pendingTaskCount: 0,
runningTaskCount: 0,
waitingForConfirmationCount: 0,
waitingForUserInputCount: 0,
reconciliationAgentCount: 1,
privateDiagnostic: autonomousPlayablePartialCanary,
};
const taskPath = path.join(
state.projectRoot,
'.agent/runtime/tasks/project-supervisor.jsonl',
);
const runtimePath = path.join(
state.projectRoot,
'.agent/runtime/agents/project-supervisor.json',
);
const conversationPath = agentConversationPath(
projectSupervisorAgentId,
supervisorSwarmSessionId,
);
await fs.mkdir(path.dirname(taskPath), { recursive: true });
await fs.mkdir(path.dirname(runtimePath), { recursive: true });
await fs.mkdir(path.dirname(conversationPath), { recursive: true });
await fs.writeFile(
taskPath,
`${JSON.stringify({
agentId: projectSupervisorAgentId,
runId: syntheticAutonomousPlayableRunId,
status: 'budget-exhausted',
phase: 'budget-exhausted',
task: autonomousPlayablePartialCanary,
})}\n`,
);
await fs.writeFile(
runtimePath,
JSON.stringify({
agentId: projectSupervisorAgentId,
runId: syntheticAutonomousPlayableRunId,
status: 'needs-reconciliation',
phase: 'needs-reconciliation',
currentTask: autonomousPlayablePartialCanary,
}),
);
await fs.writeFile(
conversationPath,
`${JSON.stringify({
role: 'user',
content: autonomousPlayablePartialCanary,
})}\n`,
);
syntheticAutonomousPlayableCollectorEvidence =
await collectPartialSupervisorAutonomousPlayableEvidence();
} finally {
state.projectRoot = previousProjectRootForAutonomousPlayable;
state.initialTask = previousInitialTaskForAutonomousPlayable;
state.supervisorAutonomousPlayable.turnReport =
previousAutonomousPlayableTurnReport;
state.supervisorAutonomousPlayable.privateValues =
previousAutonomousPlayablePrivateValues;
state.supervisorSwarm.privateValues = previousSupervisorSwarmPrivateValues;
state.supervisorSwarm.initialProviderBatch =
previousSupervisorSwarmInitialProviderBatch;
await fs.rm(syntheticAutonomousPlayableCollectorRoot, {
recursive: true,
force: true,
});
}
const autonomousPlayablePartialCollectorPrivacyValidated =
syntheticAutonomousPlayableCollectorEvidence.evidenceCompleteness ===
'partial' &&
syntheticAutonomousPlayableCollectorEvidence.rootRunObserved === true &&
syntheticAutonomousPlayableCollectorEvidence.parentTaskStatus ===
'budget-exhausted' &&
syntheticAutonomousPlayableCollectorEvidence.parentTaskPhase ===
'budget-exhausted' &&
syntheticAutonomousPlayableCollectorEvidence.parentRuntimeStatus ===
'needs-reconciliation' &&
syntheticAutonomousPlayableCollectorEvidence.parentRuntimePhase ===
'needs-reconciliation' &&
syntheticAutonomousPlayableCollectorEvidence.supervisorUserMessageCount ===
1 &&
syntheticAutonomousPlayableCollectorEvidence.turnReportPrivateLeakCount ===
1 &&
!JSON.stringify(syntheticAutonomousPlayableCollectorEvidence).includes(
autonomousPlayablePartialCanary,
);
state.initialRunId = previousInitialRunIdForAutonomousPlayable;
state.suite = previousSuiteForAutonomousPlayable;
assert(
autonomousPlayableSuiteRegistered &&
autonomousPlayablePartialEvidenceValidated &&
autonomousPlayablePartialCollectorPrivacyValidated,
'agent-runtime-real-e2e-self-test-autonomous-playable-suite-invalid',
);
const rootToolPlanHandoffCommand =
'npm --prefix apps/ai-game-creator-shell run agent-runtime:supervisor-swarm-tool-plan-handoff-runner-kill-real-e2e --';
const shellToolPlanHandoffCommand =
'node scripts/agent-runtime-real-e2e.mjs --suite supervisor-swarm-tool-plan-handoff-runner-kill';
const originalToolPlanHandoffProxy =
state.supervisorSwarm.toolPlanHandoffProxy;
state.supervisorSwarm.toolPlanHandoffProxy = {};
const toolPlanHandoffCleanupRegistered =
supervisorSwarmToolPlanHandoffProxyNeedsCleanup();
state.supervisorSwarm.toolPlanHandoffProxy = originalToolPlanHandoffProxy;
const toolPlanHandoffPartialEvidence =
supervisorSwarmToolPlanHandoffSnapshotEvidence();
const toolPlanHandoffPackageCommandsRegistered =
rootPackage.scripts?.[
'ai-game-creator-shell:agent-runtime:supervisor-swarm-tool-plan-handoff-runner-kill-real-e2e'
] === rootToolPlanHandoffCommand &&
shellPackage.scripts?.[
'agent-runtime:supervisor-swarm-tool-plan-handoff-runner-kill-real-e2e'
] === shellToolPlanHandoffCommand;
const toolPlanHandoffSourceGuardRegistered =
sourceAppDataDirectoryEventIsViolation(
`${toolPlanHandoffProfile.prefix}synthetic`,
toolPlanHandoffProfile.prefix,
{ exists: false, fingerprint: null },
);
const toolPlanHandoffSuiteRegistered =
toolPlanHandoffParsedArguments.suite ===
supervisorSwarmToolPlanHandoffRunnerKillSuite &&
isSupervisorSwarmToolPlanHandoffRunnerKillSuite() &&
isSupervisorSwarmSuite() &&
isIsolatedRunnerSuite() &&
isolatedSuiteProtectsSourceAppData() &&
toolPlanHandoffProfile.prefix ===
'.agent-runtime-real-e2e-supervisor-swarm-tool-plan-handoff-runner-kill-' &&
toolPlanHandoffProfile.codePrefix ===
'supervisor-swarm-tool-plan-handoff-runner-kill-appdata' &&
toolPlanHandoffProfile.sentinelName ===
supervisorSwarmToolPlanHandoffRunnerKillAppDataSentinelFileName &&
toolPlanHandoffProfile.sentinelSchema ===
supervisorSwarmToolPlanHandoffRunnerKillAppDataSentinelSchema &&
toolPlanHandoffSourceGuardRegistered &&
toolPlanHandoffPackageCommandsRegistered &&
toolPlanHandoffCleanupRegistered &&
toolPlanHandoffPartialEvidence.toolPlanHandoffModeEnabled === true &&
Object.hasOwn(
toolPlanHandoffPartialEvidence,
'toolPlanHandoffNetworkReplayCount',
);
state.suite = previousSuiteForToolPlanHandoff;
const syntheticToolPlanHandoffEntry = {
response: {
toolCalls: [
{
id: 'synthetic-plan-call',
name: 'update_agent_plan',
arguments: JSON.stringify({
explanation: 'synthetic plan',
steps: [{ step: 'delegate', status: 'in_progress' }],
}),
},
...['design', 'quality'].map((agentId) => ({
id: `synthetic-${agentId}-call`,
name: 'runtime_tool_agent_delegate',
arguments: JSON.stringify({
reason: `delegate ${agentId}`,
input: { agentId },
}),
})),
],
},
};
const syntheticToolPlanHandoffPlan = parseSupervisorSwarmToolPlanHandoffPlan(
syntheticToolPlanHandoffEntry,
);
const syntheticNormalizedPlanUpdate = normalizeSupervisorSwarmToolPlanUpdate({
explanation: ` ${'x'.repeat(241)} `,
steps: [{ step: ` ${'y'.repeat(181)} `, status: ' pending ' }],
});
const toolPlanHandoffPlanProjectionValidated =
syntheticToolPlanHandoffPlan.thinkingSummary === 'synthetic plan' &&
syntheticToolPlanHandoffPlan.planUpdate?.steps?.length === 1 &&
syntheticToolPlanHandoffPlan.actions.length === 2 &&
syntheticToolPlanHandoffPlan.actions.every(
(action) => action.tool === 'agent.delegate',
) &&
syntheticToolPlanHandoffPlan.response === '' &&
syntheticNormalizedPlanUpdate.explanation === `${'x'.repeat(240)}…` &&
syntheticNormalizedPlanUpdate.steps[0].step === `${'y'.repeat(180)}…` &&
syntheticNormalizedPlanUpdate.steps[0].status === 'pending' &&
hashJsonValue(syntheticToolPlanHandoffPlan) ===
hashJsonValue(canonicalJsonValue(syntheticToolPlanHandoffPlan));
const toolPlanHandoffEvidenceFieldsRegistered = [
'toolPlanHandoffModeEnabled',
'toolPlanHandoffCheckpointCaptured',
'toolPlanHandoffNetworkReplayCount',
'toolPlanHandoffLifecycleClosedExactlyOnce',
'toolPlanHandoffAuditIdempotent',
'toolPlanHandoffRecoveredPlanFingerprintMatched',
'toolPlanHandoffCapabilityLeakCount',
'toolPlanHandoffPrePersistUnknownResultWindowCovered',
].every((field) =>
Object.hasOwn(supervisorSwarmEvidenceFieldTemplate(), field),
);
assert(
toolPlanHandoffSuiteRegistered &&
toolPlanHandoffPlanProjectionValidated &&
toolPlanHandoffEvidenceFieldsRegistered &&
supervisorSwarmEvidenceFieldTemplate()
.toolPlanHandoffPrePersistUnknownResultWindowCovered === false,
'agent-runtime-real-e2e-self-test-tool-plan-handoff-suite-invalid',
);
const previousInitialRunId = state.initialRunId;
const syntheticFinalReplyRunId = 'synthetic-final-reply-run';
state.initialRunId = syntheticFinalReplyRunId;
const syntheticToolPlanStarted = {
recordType: 'agent.runtime.provider_request.lifecycle',
status: 'started',
agentId: projectSupervisorAgentId,
runId: syntheticFinalReplyRunId,
requestKind: 'tool-plan',
requestId: 'synthetic-tool-plan-request',
};
const syntheticVerificationAudit = {
recordType: 'agent.runtime.project.verify',
agentId: projectSupervisorAgentId,
runId: syntheticFinalReplyRunId,
actionId: 'synthetic-verification-action',
status: 'completed',
exitCode: 0,
timedOut: false,
};
const syntheticVerificationReceipt = {
recordType: 'agent.runtime.action_receipt',
agentId: projectSupervisorAgentId,
runId: syntheticFinalReplyRunId,
actionId: syntheticVerificationAudit.actionId,
tool: 'project.verify',
status: 'ok',
};
const syntheticVerificationObservation = {
recordType: 'agent.runtime.tool_observation',
agentId: projectSupervisorAgentId,
runId: syntheticFinalReplyRunId,
actionId: syntheticVerificationAudit.actionId,
tool: 'project.verify',
status: 'ok',
};
const syntheticFinalReplyStarted = {
recordType: 'agent.runtime.provider_request.lifecycle',
status: 'started',
agentId: projectSupervisorAgentId,
taskId: 'synthetic-final-reply-task',
sessionId: supervisorSwarmSessionId,
runId: syntheticFinalReplyRunId,
requestKind: 'final-reply',
requestId: 'synthetic-final-reply-request',
requestSlot: 'synthetic-final-reply-slot',
};
const syntheticDeliveries = [
['synthetic-design', null],
['synthetic-quality', null],
['synthetic-repair', 'synthetic-quality'],
].map(([delegationId, repairOfDelegationId]) => ({
parentAgentId: projectSupervisorAgentId,
parentSessionId: supervisorSwarmSessionId,
parentRunId: syntheticFinalReplyRunId,
delegationId,
repairOfDelegationId,
status: 'claimed-by-parent',
terminalStatus: 'completed',
}));
const syntheticFinalReplyPrerequisites =
supervisorSwarmFinalReplyFaultPrerequisites(
{
deliveries: syntheticDeliveries,
claims: [
{
status: 'observed',
receipts: [
{ delegationId: 'synthetic-design' },
{ delegationId: 'synthetic-quality' },
],
},
{
status: 'observed',
receipts: [{ delegationId: 'synthetic-repair' }],
},
],
agentDb: [
syntheticToolPlanStarted,
syntheticVerificationAudit,
syntheticVerificationReceipt,
syntheticVerificationObservation,
syntheticFinalReplyStarted,
],
supervisorConversation: [],
projectRevision: { revision: 2 },
},
syntheticFinalReplyStarted,
{ sequence: 7, acceptedAtMs: 1234 },
);
const syntheticInvalidFinalReplyPrerequisites =
supervisorSwarmFinalReplyFaultPrerequisites(
{
deliveries: syntheticDeliveries,
claims: [
{
status: 'observed',
receipts: [
{ delegationId: 'synthetic-design' },
{ delegationId: 'synthetic-quality' },
],
},
{
status: 'observed',
receipts: [{ delegationId: 'synthetic-repair' }],
},
],
agentDb: [
syntheticToolPlanStarted,
syntheticFinalReplyStarted,
syntheticVerificationAudit,
syntheticVerificationReceipt,
syntheticVerificationObservation,
],
supervisorConversation: [{ role: 'assistant' }],
projectRevision: { revision: 2 },
},
syntheticFinalReplyStarted,
{ sequence: 7, acceptedAtMs: 1234 },
);
state.initialRunId = previousInitialRunId;
assert(
syntheticFinalReplyPrerequisites.preconditionsValid &&
syntheticFinalReplyPrerequisites.requestKind === 'final-reply' &&
syntheticFinalReplyPrerequisites.deliveryCount === 3 &&
syntheticFinalReplyPrerequisites.repairDeliveryCount === 1 &&
syntheticFinalReplyPrerequisites.observedClaimReceiptCount === 3 &&
syntheticFinalReplyPrerequisites.runtimeVerificationCount === 1 &&
syntheticFinalReplyPrerequisites.parentToolPlanStartedCount === 1 &&
!syntheticInvalidFinalReplyPrerequisites.preconditionsValid &&
JSON.stringify(
syntheticInvalidFinalReplyPrerequisites.invalidPrerequisiteFields,
) === JSON.stringify(['assistantAbsent']) &&
supervisorSwarmHostVerificationPassed({
stdout: commandPassedMarker,
stderr: '',
}) &&
!supervisorSwarmHostVerificationPassed({
stdout: commandFailureMarker,
stderr: '',
}) &&
supervisorSwarmFinalReplyFaultInjectionAllowed({
preconditionsValid: true,
}) &&
!supervisorSwarmFinalReplyFaultInjectionAllowed({
preconditionsValid: false,
}) &&
supervisorSwarmResidualSidecarsEmpty({ finalizations: 0, retries: 0 }) &&
!supervisorSwarmResidualSidecarsEmpty({
finalizations: 1,
retries: 0,
}),
'agent-runtime-real-e2e-self-test-final-reply-fault-prerequisite-invalid',
);
const newlineValue = 'private first line\nprivate second line';
const quotedValue = 'private value says "quoted"';
const backslashValue = 'private\\nested\\value';
const combinedValue = `${newlineValue}\n${quotedValue}\n${backslashValue}`;
const exactSecretCounts = {
newline: countExactSecrets(
Buffer.from(JSON.stringify({ value: newlineValue })),
[newlineValue],
),
quote: countExactSecrets(
Buffer.from(JSON.stringify({ value: quotedValue })),
[quotedValue],
),
backslash: countExactSecrets(
Buffer.from(JSON.stringify({ value: backslashValue })),
[backslashValue],
),
combined: countExactSecrets(
Buffer.from(JSON.stringify({ value: combinedValue })),
[combinedValue],
),
escapedFallback: countExactSecrets(
Buffer.from(
`prefix:${JSON.stringify(combinedValue).slice(1, -1)}:suffix`,
),
[combinedValue],
),
duplicateSecretInput: countExactSecrets(
Buffer.from(JSON.stringify({ value: combinedValue })),
[combinedValue, combinedValue],
),
};
assert(
Object.values(exactSecretCounts).every((count) => count === 1),
'agent-runtime-real-e2e-self-test-exact-secret-count-invalid',
);
const previousPrivateValueScopeState = {
secrets: state.secrets,
transcriptOnlySecrets: state.transcriptOnlySecrets,
privateValues: state.supervisorSwarm.privateValues,
transcriptScanner: state.transcriptScanner,
};
const syntheticTransportSecret =
'synthetic-private-transport-secret-for-scope-self-test';
const syntheticPrivateOutput = 'synthetic-private-output-for-scope-self-test';
state.secrets = [];
state.transcriptOnlySecrets = [];
state.supervisorSwarm.privateValues = [];
state.transcriptScanner = new StreamingSecretScanner([]);
registerSupervisorSwarmPrivateTransportValues([syntheticTransportSecret]);
registerSupervisorSwarmPrivateOutputValues([syntheticPrivateOutput]);
const privateOutputSplitAt = Math.floor(syntheticPrivateOutput.length / 2);
state.transcriptScanner.scan(
'synthetic-private-output',
syntheticPrivateOutput.slice(0, privateOutputSplitAt),
);
state.transcriptScanner.scan(
'synthetic-private-output',
syntheticPrivateOutput.slice(privateOutputSplitAt),
);
const scopedPrivateOutputValidated =
state.secrets.includes(syntheticTransportSecret) &&
!state.secrets.includes(syntheticPrivateOutput) &&
state.transcriptOnlySecrets.includes(syntheticPrivateOutput) &&
state.supervisorSwarm.privateValues.includes(syntheticTransportSecret) &&
state.supervisorSwarm.privateValues.includes(syntheticPrivateOutput) &&
state.transcriptScanner.count === 1 &&
countExactSecrets(
JSON.stringify({ privateOutput: syntheticPrivateOutput }),
state.secrets,
) === 0 &&
countExactSecrets(
JSON.stringify({ privateOutput: syntheticPrivateOutput }),
[...state.secrets, ...state.transcriptOnlySecrets],
) === 1;
state.secrets = previousPrivateValueScopeState.secrets;
state.transcriptOnlySecrets =
previousPrivateValueScopeState.transcriptOnlySecrets;
state.supervisorSwarm.privateValues =
previousPrivateValueScopeState.privateValues;
state.transcriptScanner = previousPrivateValueScopeState.transcriptScanner;
assert(
scopedPrivateOutputValidated,
'agent-runtime-real-e2e-self-test-private-output-scope-invalid',
);
const syntheticRecoveredRepairSessionId = 'synthetic-repair-session';
const syntheticRecoveredRepairIdentity = {
agentId: 'synthetic-repair-agent',
runId: 'synthetic-repair-run',
actionId: 'synthetic-repair-action',
actionFingerprint: 'synthetic-repair-fingerprint',
tool: 'project.patchset',
};
const matchesSyntheticRecoveredRepair = (record) =>
Object.entries(syntheticRecoveredRepairIdentity).every(
([field, value]) => record[field] === value,
);
const syntheticRecoveredRepairRecords = (requirementRecordType) => [
{
...syntheticRecoveredRepairIdentity,
recordType: requirementRecordType,
...(requirementRecordType ===
'agent.runtime.provider_action_batch.confirmation_required'
? {
sessionId: syntheticRecoveredRepairSessionId,
batchId: 'synthetic-repair-batch',
actionCount: 1,
actionIndex: 0,
}
: { summary: 'synthetic legacy confirmation requirement' }),
},
{
...syntheticRecoveredRepairIdentity,
recordType: 'agent.runtime.tool_confirmation.approved',
sessionId: syntheticRecoveredRepairSessionId,
confirmedRunId: syntheticRecoveredRepairIdentity.runId,
commandId: syntheticRecoveredRepairIdentity.tool,
},
{
...syntheticRecoveredRepairIdentity,
recordType: 'agent.runtime.action_receipt',
sessionId: syntheticRecoveredRepairSessionId,
executionMode: 'confirmation',
status: 'ok',
},
];
const inspectSyntheticRecoveredRepair = (records) =>
inspectSupervisorSwarmRecoveredRepairConfirmationLifecycle(
records,
matchesSyntheticRecoveredRepair,
syntheticRecoveredRepairSessionId,
syntheticRecoveredRepairIdentity.runId,
);
const syntheticModernRecoveredRepairRecords = syntheticRecoveredRepairRecords(
'agent.runtime.provider_action_batch.confirmation_required',
);
const syntheticLegacyRecoveredRepairRecords = syntheticRecoveredRepairRecords(
'agent.runtime.tool_confirmation_required',
);
const syntheticModernRecoveredRepairLifecycle =
inspectSyntheticRecoveredRepair(syntheticModernRecoveredRepairRecords);
const syntheticLegacyRecoveredRepairLifecycle =
inspectSyntheticRecoveredRepair(syntheticLegacyRecoveredRepairRecords);
const syntheticRecoveredRepairLifecycles = [
syntheticModernRecoveredRepairLifecycle,
syntheticLegacyRecoveredRepairLifecycle,
];
const syntheticRecoveredRepairNegativeLifecycles = [
syntheticModernRecoveredRepairRecords,
syntheticLegacyRecoveredRepairRecords,
].flatMap((records) => [
...records.map((record) =>
inspectSyntheticRecoveredRepair([...records, { ...record }]),
),
...records.map((_, missingIndex) =>
inspectSyntheticRecoveredRepair(
records.filter((__, recordIndex) => recordIndex !== missingIndex),
),
),
]);
const syntheticRecoveredRepairConflictLifecycle =
inspectSyntheticRecoveredRepair([
syntheticModernRecoveredRepairRecords[0],
syntheticLegacyRecoveredRepairRecords[0],
...syntheticModernRecoveredRepairRecords.slice(1),
]);
const syntheticRecoveredRepairAutoReceiptLifecycle =
inspectSyntheticRecoveredRepair(
syntheticModernRecoveredRepairRecords.map((record) =>
record.recordType === 'agent.runtime.action_receipt'
? { ...record, executionMode: 'auto' }
: record,
),
);
const syntheticRecoveredRepairWrongRunLifecycle =
inspectSyntheticRecoveredRepair(
syntheticModernRecoveredRepairRecords.map((record) =>
record.recordType === 'agent.runtime.tool_confirmation.approved'
? { ...record, confirmedRunId: 'synthetic-other-run' }
: record,
),
);
const syntheticRecoveredRepairMissingSessionLifecycles =
syntheticModernRecoveredRepairRecords.map((_, missingSessionIndex) =>
inspectSyntheticRecoveredRepair(
syntheticModernRecoveredRepairRecords.map((record, recordIndex) => {
if (recordIndex !== missingSessionIndex) return record;
const recordWithoutSession = { ...record };
delete recordWithoutSession.sessionId;
return recordWithoutSession;
}),
),
);
const syntheticRecoveredRepairWrongSessionLifecycle =
inspectSyntheticRecoveredRepair(
syntheticModernRecoveredRepairRecords.map((record) =>
isNonEmptyString(record.sessionId)
? { ...record, sessionId: 'synthetic-other-session' }
: record,
),
);
const syntheticLegacyRecoveredRepairWrongSessionLifecycle =
inspectSyntheticRecoveredRepair([
{
...syntheticLegacyRecoveredRepairRecords[0],
sessionId: 'synthetic-other-session',
},
...syntheticLegacyRecoveredRepairRecords.slice(1),
]);
const syntheticRecoveredRepairOutOfOrderLifecycle =
inspectSyntheticRecoveredRepair([
syntheticModernRecoveredRepairRecords[1],
syntheticModernRecoveredRepairRecords[0],
syntheticModernRecoveredRepairRecords[2],
]);
assert(
syntheticRecoveredRepairLifecycles.every(
(lifecycle) =>
lifecycle.valid &&
lifecycle.confirmationRequirements.length === 1 &&
lifecycle.approvals.length === 1 &&
lifecycle.receipts.length === 1,
) &&
syntheticRecoveredRepairNegativeLifecycles.every(
(lifecycle) => !lifecycle.valid,
) &&
!Object.hasOwn(syntheticLegacyRecoveredRepairRecords[0], 'sessionId') &&
syntheticLegacyRecoveredRepairLifecycle.valid &&
syntheticRecoveredRepairMissingSessionLifecycles.every(
(lifecycle) => !lifecycle.valid,
) &&
!syntheticRecoveredRepairConflictLifecycle.valid &&
!syntheticRecoveredRepairAutoReceiptLifecycle.valid &&
!syntheticRecoveredRepairWrongRunLifecycle.valid &&
!syntheticRecoveredRepairWrongSessionLifecycle.valid &&
!syntheticLegacyRecoveredRepairWrongSessionLifecycle.valid &&
!syntheticRecoveredRepairOutOfOrderLifecycle.valid,
'agent-runtime-real-e2e-self-test-recovered-repair-confirmation-lifecycle-invalid',
);
const evidenceMetadata = {
kind: 'project.verify.metadata',
path: 'game/metadata-only.txt',
sha256: 'a'.repeat(64),
};
const expectedPrivateValues = [
'private static delivery task',
'private static acceptance criterion',
'private static result summary',
'private evidence summary body',
'private professional conversation body',
];
const dynamicPrivateValues = collectSupervisorSwarmDynamicPrivateValues({
deliveries: [
{
task: expectedPrivateValues[0],
acceptanceCriteria: [expectedPrivateValues[1]],
resultSummary: expectedPrivateValues[2],
structuredResult: {
evidence: [
{
...evidenceMetadata,
summary: expectedPrivateValues[3],
},
],
},
},
],
professionalConversations: [
{ messages: [{ content: expectedPrivateValues[4] }] },
],
isolatedGroups: [],
isolatedInstances: [],
isolatedResults: [],
isolatedConversations: [],
});
assert(
expectedPrivateValues.every((value) =>
dynamicPrivateValues.includes(value),
),
'agent-runtime-real-e2e-self-test-dynamic-private-body-missing',
);
assert(
Object.values(evidenceMetadata).every(
(value) => !dynamicPrivateValues.includes(value),
),
'agent-runtime-real-e2e-self-test-evidence-metadata-private',
);
const seedPrivateValues = supervisorSwarmSeedPrivateValues(
'private repository instructions body',
);
assert(
supervisorSwarmIsolatedReviews.every(
(review) =>
seedPrivateValues.includes(review.content) &&
seedPrivateValues.includes(review.requirement) &&
review.boundaryTerms.every((term) => !seedPrivateValues.includes(term)),
),
'agent-runtime-real-e2e-self-test-generic-boundary-term-private',
);
const syntheticMixedGroups = [
{
delegationGroupId: 'synthetic-followup-group',
request: {
children: supervisorSwarmFollowupIsolatedReviews.map((review) => ({
expectedArtifacts: [review.path],
})),
},
},
{
delegationGroupId: 'synthetic-initial-group',
request: {
children: supervisorSwarmInitialIsolatedReviews.map((review) => ({
expectedArtifacts: [review.path],
})),
},
},
];
const syntheticMixedEntries = supervisorSwarmMixedIsolatedGroupEntries(
syntheticMixedGroups,
supervisorSwarmIsolatedReviewGroups,
);
const syntheticSingleGroupEntries = supervisorSwarmMixedIsolatedGroupEntries(
[
{
delegationGroupId: 'synthetic-single-group',
request: {
children: supervisorSwarmIsolatedReviews.map((review) => ({
expectedArtifacts: [review.path],
})),
},
},
],
[supervisorSwarmIsolatedReviews],
);
const syntheticReadyGroupIds = supervisorSwarmReadyIsolatedGroupIds(
`readyIsolatedJoins: ${JSON.stringify({
ready: true,
joins: syntheticMixedEntries.map(({ group }) => ({
delegationGroupId: group.delegationGroupId,
})),
})}\n\nagentId: ${projectSupervisorAgentId}`,
);
const syntheticObservedJoinClaim = supervisorSwarmObservedJoinClaimForGroups(
[
{
schemaVersion: isolatedAgentJoinClaimSchemaVersion,
parentAgentId: projectSupervisorAgentId,
parentRunId: 'synthetic-parent-run',
actionId: 'synthetic-claim-action',
status: 'observed',
joins: syntheticMixedEntries.map(({ group }) => ({
delegationGroupId: group.delegationGroupId,
})),
},
],
syntheticReadyGroupIds,
);
const syntheticWriteScopeRoots = supervisorSwarmIsolatedWriteScopeRoots(
supervisorSwarmIsolatedReviewGroups.flatMap((reviews) =>
reviews.map((review) => ({ writeScopes: [review.scope] })),
),
);
let syntheticOverlappingWriteScopesRejected = false;
try {
supervisorSwarmIsolatedWriteScopeRoots([
{ writeScopes: ['e2e/**'] },
{ writeScopes: ['e2e/isolated-a/**'] },
]);
} catch (error) {
syntheticOverlappingWriteScopesRejected =
error?.code === 'supervisor-swarm-mixed-child-write-scopes-overlap';
}
const syntheticFollowupOrderValidated =
supervisorSwarmFollowupBeforeClaimOrderValid(3, 5, [8, 9]) &&
!supervisorSwarmFollowupBeforeClaimOrderValid(3, 8, [8, 9]);
const originalSuite = state.suite;
const originalInitialRunId = state.initialRunId;
state.suite = supervisorSwarmStaticIsolatedAutonomousChatSuite;
const multiGroupPolicy = expectedSupervisorSwarmCollaborationPolicy();
const multiGroupCount = supervisorSwarmExpectedIsolatedReviewGroups().length;
const syntheticSnapshotExpected = {
projectId: 'synthetic-project-id',
parentAgentId: projectSupervisorAgentId,
parentRunId: 'synthetic-parent-run',
boundFrom: supervisorCollaborationPolicySnapshotInitialBatchBinding,
policy: multiGroupPolicy,
policyFingerprint: hashValue(JSON.stringify(multiGroupPolicy)),
};
const syntheticSnapshotBindingBatch = {
schemaVersion: providerActionBatchSchemaVersion,
batchId: 'synthetic-provider-batch',
projectId: syntheticSnapshotExpected.projectId,
agentId: projectSupervisorAgentId,
taskId: 'synthetic-parent-task',
sessionId: supervisorSwarmSessionId,
runId: syntheticSnapshotExpected.parentRunId,
status: 'waiting-confirmation',
collaborationContract: {
schemaVersion: supervisorCollaborationContractSchemaVersion,
policySchemaVersion: supervisorCollaborationPolicySchemaVersion,
policySnapshot: multiGroupPolicy,
policyFingerprint: syntheticSnapshotExpected.policyFingerprint,
contractFingerprint: hashValue('synthetic-collaboration-contract'),
},
};
const syntheticSnapshotBindingBatchAccepted =
supervisorSwarmInitialBatchBindsPolicySnapshot(
syntheticSnapshotBindingBatch,
syntheticSnapshotExpected.parentRunId,
);
const syntheticSnapshotBindingBatchRejections = [
{ ...syntheticSnapshotBindingBatch, status: 'aborted' },
{ ...syntheticSnapshotBindingBatch, collaborationContract: null },
{ ...syntheticSnapshotBindingBatch, agentId: 'synthetic-other-agent' },
{ ...syntheticSnapshotBindingBatch, runId: 'synthetic-other-run' },
{ ...syntheticSnapshotBindingBatch, schemaVersion: 'legacy-v1' },
].every(
(batch) =>
!supervisorSwarmInitialBatchBindsPolicySnapshot(
batch,
syntheticSnapshotExpected.parentRunId,
),
);
const syntheticSnapshotIdentity = {
schemaVersion: supervisorCollaborationPolicySnapshotSchemaVersion,
...syntheticSnapshotExpected,
};
const syntheticSnapshot = {
...syntheticSnapshotIdentity,
snapshotFingerprint: hashJsonValue(syntheticSnapshotIdentity),
boundAt: 1_784_305_826,
};
const syntheticSnapshotInspection =
validateSupervisorSwarmCollaborationPolicySnapshot(
syntheticSnapshot,
syntheticSnapshotExpected,
);
const syntheticSnapshotBinding =
supervisorSwarmCollaborationPolicySnapshotBinding(syntheticSnapshot);
const syntheticSnapshotBindingInspection =
validateSupervisorSwarmCollaborationPolicySnapshotBinding(
syntheticSnapshotBinding,
syntheticSnapshot,
);
const syntheticSnapshotBytes = JSON.stringify(syntheticSnapshot);
const syntheticSnapshotBindingBytes = JSON.stringify(
syntheticSnapshotBinding,
);
const syntheticDriftedPolicy = driftedSupervisorSwarmCollaborationPolicy();
state.initialRunId = syntheticSnapshotExpected.parentRunId;
const syntheticDriftObservationCount =
supervisorSwarmCollaborationPolicyDriftObservationCount([
{
recordType: 'agent.runtime.tool_observation',
agentId: projectSupervisorAgentId,
runId: syntheticSnapshotExpected.parentRunId,
tool: 'agent.run_status',
status: 'ok',
summary: '项目协作策略已漂移,当前父 run 继续使用已绑定快照',
},
]);
state.initialRunId = originalInitialRunId;
let syntheticSnapshotTamperRejected = false;
try {
validateSupervisorSwarmCollaborationPolicySnapshot(
{ ...syntheticSnapshot, snapshotFingerprint: '0'.repeat(64) },
syntheticSnapshotExpected,
);
} catch (error) {
syntheticSnapshotTamperRejected =
error?.code === 'supervisor-swarm-collaboration-policy-snapshot-invalid';
}
let syntheticSnapshotBindingTamperRejected = false;
try {
validateSupervisorSwarmCollaborationPolicySnapshotBinding(
{ ...syntheticSnapshotBinding, boundAt: syntheticSnapshot.boundAt + 1 },
syntheticSnapshot,
);
} catch (error) {
syntheticSnapshotBindingTamperRejected =
error?.code ===
'supervisor-swarm-collaboration-policy-snapshot-binding-invalid';
}
const syntheticMissingSnapshotSafe =
inspectSupervisorSwarmCollaborationPolicySnapshot(
null,
syntheticSnapshotExpected,
).identityHashMatched === false;
const syntheticMissingBindingSafe =
inspectSupervisorSwarmCollaborationPolicySnapshotBinding(
null,
syntheticSnapshot,
).snapshotMatched === false;
const syntheticSnapshotDuplicateCount =
duplicateSupervisorSwarmCollaborationPolicySnapshotCount([
syntheticSnapshot,
]);
const syntheticSnapshotBindingDuplicateCount =
duplicateSupervisorSwarmCollaborationPolicySnapshotBindingCount([
syntheticSnapshotBinding,
]);
const syntheticEnospcDiagnostic = safeProcessFailureDiagnostic({
code: 1,
stderr: 'No space left on device (os error 28)',
});
const syntheticChatSessionFailureEvidence = buildSupervisorSwarmEvidence({
chatSessionUnexpectedlyClosed: true,
chatSessionFailureKind: syntheticEnospcDiagnostic.failureKind,
chatSessionExitCode: syntheticEnospcDiagnostic.exitCode,
chatSessionCloseSignal: syntheticEnospcDiagnostic.signal,
chatSessionProcessErrorCode: syntheticEnospcDiagnostic.processErrorCode,
chatSessionStderrChars: syntheticEnospcDiagnostic.stderrChars,
chatSessionStderrSha256: syntheticEnospcDiagnostic.stderrSha256,
});
state.suite = supervisorSwarmCollaborationPolicyMixedRecoverySuite;
const recoveryPolicy = expectedSupervisorSwarmCollaborationPolicy();
const recoveryGroupCount =
supervisorSwarmExpectedIsolatedReviewGroups().length;
state.suite = supervisorSwarmAutonomousChatSuite;
const syntheticSnapshotBindingBatchSuiteIndependent =
supervisorSwarmInitialBatchBindsPolicySnapshot(
syntheticSnapshotBindingBatch,
syntheticSnapshotExpected.parentRunId,
);
state.suite = originalSuite;
assert(
syntheticSnapshotInspection.identityHashMatched &&
syntheticSnapshotBindingInspection.snapshotMatched &&
syntheticSnapshotBytes === JSON.stringify(syntheticSnapshot) &&
syntheticSnapshotBindingBytes ===
JSON.stringify(syntheticSnapshotBinding) &&
multiGroupPolicy.minIsolatedGroupsBeforeClaim === 2 &&
syntheticDriftedPolicy.minIsolatedGroupsBeforeClaim === 1 &&
syntheticDriftObservationCount === 1 &&
syntheticSnapshotTamperRejected &&
syntheticSnapshotBindingTamperRejected &&
syntheticMissingSnapshotSafe &&
syntheticMissingBindingSafe &&
syntheticSnapshotDuplicateCount === 0 &&
syntheticSnapshotBindingDuplicateCount === 0 &&
syntheticSnapshotBindingBatchAccepted &&
syntheticSnapshotBindingBatchRejections &&
syntheticSnapshotBindingBatchSuiteIndependent &&
syntheticEnospcDiagnostic.failureKind === 'enospc' &&
syntheticEnospcDiagnostic.stderrChars > 0 &&
/^[0-9a-f]{64}$/u.test(syntheticEnospcDiagnostic.stderrSha256) &&
syntheticChatSessionFailureEvidence.chatSessionUnexpectedlyClosed ===
true &&
syntheticChatSessionFailureEvidence.chatSessionFailureKind === 'enospc',
'agent-runtime-real-e2e-self-test-collaboration-policy-snapshot-binding-invalid',
);
assert(
JSON.stringify(
syntheticMixedEntries.map(({ groupIndex }) => groupIndex),
) === JSON.stringify([0, 1]) &&
JSON.stringify(
syntheticSingleGroupEntries.map(({ groupIndex }) => groupIndex),
) === JSON.stringify([0]) &&
supervisorSwarmIsolatedReviewGroupIndex(
supervisorSwarmIsolatedReviews.map((review) => ({
expectedArtifacts: [review.path],
})),
) === -1 &&
JSON.stringify(syntheticReadyGroupIds) ===
JSON.stringify(
syntheticMixedGroups.map((group) => group.delegationGroupId).sort(),
) &&
syntheticObservedJoinClaim.actionId === 'synthetic-claim-action' &&
syntheticWriteScopeRoots.length ===
supervisorSwarmIsolatedReviews.length &&
new Set(syntheticWriteScopeRoots).size ===
supervisorSwarmIsolatedReviews.length &&
syntheticOverlappingWriteScopesRejected &&
syntheticFollowupOrderValidated &&
multiGroupPolicy.minIsolatedChildren === 2 &&
Object.hasOwn(multiGroupPolicy, 'minIsolatedGroupsBeforeClaim') &&
multiGroupPolicy.minIsolatedGroupsBeforeClaim === 2 &&
multiGroupCount === 2 &&
recoveryPolicy.minIsolatedChildren === 3 &&
!Object.hasOwn(recoveryPolicy, 'minIsolatedGroupsBeforeClaim') &&
(recoveryPolicy.minIsolatedGroupsBeforeClaim ?? 0) === 0 &&
recoveryGroupCount === 1,
'agent-runtime-real-e2e-self-test-mixed-isolated-groups-invalid',
);
const syntheticIdentity = {
agentId: 'private-agent-id',
taskId: 'private-task-id',
sessionId: 'private-session-id',
runId: 'private-run-id',
source: 'private-source',
};
const persistedAuditEnvelope = {
schemaVersion: 'game-creator-agent-db.v1',
updatedAt: 1_784_305_826,
};
const retryableProtocolErrorKinds = toolPlanProtocolErrorKinds.filter(
(kind) => kind !== 'catalog-binding',
);
const repairRecords = retryableProtocolErrorKinds.map((kind, index) => ({
...persistedAuditEnvelope,
recordType: 'agent.runtime.tool_plan.repair',
...syntheticIdentity,
loopIteration: index,
repairAttempt: 0,
requestSlot: `loop-${index}-repair-0`,
responseFingerprint: hashValue(`private-response-${kind}`),
providerRequestIdSha256: hashValue(`private-provider-request-${kind}`),
attempt: 1,
maxAttempts: 2,
protocolErrorKind: kind,
protocolErrorSha256: hashValue(`private-error-${kind}`),
protocolErrorChars: 24,
responsePreviewSha256: hashValue(`private-preview-${kind}`),
responsePreviewChars: 26,
protocol: 'native_runtime_tools',
callIdSha256: hashValue(`private-call-${kind}`),
functionNameSha256: hashValue(`runtime_tool_${kind}`),
}));
repairRecords.push({
...repairRecords[0],
repairAttempt: 1,
requestSlot: 'loop-0-repair-1',
responseFingerprint: hashValue('private-response-shape-second'),
providerRequestIdSha256: hashValue('private-provider-request-shape-second'),
attempt: 2,
});
const fatalCatalogBindingRepair = {
...repairRecords[0],
loopIteration: retryableProtocolErrorKinds.length,
requestSlot: `loop-${retryableProtocolErrorKinds.length}-repair-0`,
responseFingerprint: hashValue('private-response-catalog-binding'),
providerRequestIdSha256: hashValue(
'private-provider-request-catalog-binding',
),
protocolErrorKind: 'catalog-binding',
};
const syntheticProtocolCallId = 'private-call-id';
const syntheticProtocolResponseId = 'private-response-id';
const normalizedProtocolRecord = {
...persistedAuditEnvelope,
recordType: 'agent.runtime.tool_plan.protocol',
...syntheticIdentity,
loopIteration: 8,
repairAttempt: 0,
requestSlot: 'loop-8-repair-0',
responseFingerprint: hashValue('private-protocol-response'),
providerRequestIdSha256: hashValue('private-protocol-provider-request'),
protocol: 'native_runtime_tools',
functionCallCount: 1,
callIdSha256s: [hashValue(syntheticProtocolCallId)],
functionNames: ['runtime_tool_file_read'],
normalizationKinds: ['complete-think-block', 'planner-commentary'],
normalizationCount: 3,
normalizedTextChars: 80,
normalizedTextSha256: hashValue('private-normalized-text'),
responseIdSha256: hashValue(syntheticProtocolResponseId),
responseIdChars: syntheticProtocolResponseId.length,
};
const toolPlanAudits = [normalizedProtocolRecord, ...repairRecords];
const fullRepairEvidence = collectToolPlanRepairAuditEvidence(toolPlanAudits);
const fatalRepairEvidence = collectToolPlanRepairAuditEvidence([
normalizedProtocolRecord,
fatalCatalogBindingRepair,
]);
const expectedRepairCounts = emptyToolPlanRepairCountsByProtocolErrorKind();
for (const kind of retryableProtocolErrorKinds) {
expectedRepairCounts[kind] = kind === 'response-shape' ? 2 : 1;
}
assert(
fullRepairEvidence.toolPlanRepairCount === 8 &&
fullRepairEvidence.toolPlanRepairedLoopCount === 7 &&
fullRepairEvidence.toolPlanSecondRepairCount === 1 &&
JSON.stringify(
fullRepairEvidence.toolPlanRepairCountsByProtocolErrorKind,
) === JSON.stringify(expectedRepairCounts) &&
sumObjectValues(
fullRepairEvidence.toolPlanRepairCountsByProtocolErrorKind,
) === fullRepairEvidence.toolPlanRepairCount &&
fullRepairEvidence.toolPlanAuditPayloadLeakCount === 0 &&
toolPlanRepairEvidenceHasNoFatalLocalRepair(fullRepairEvidence) &&
!toolPlanRepairEvidenceHasNoFatalLocalRepair(fatalRepairEvidence),
'agent-runtime-real-e2e-self-test-tool-plan-repair-aggregate-invalid',
);
const rawPayloadFields = [
'errorBody',
'detail',
'preview',
'arguments',
'body',
'text',
'protocolError',
'responsePreview',
'toolArguments',
];
const rejectedRawPayloadFieldCount = rawPayloadFields.filter(
(field) =>
!hasSafeToolPlanAuditPayload({
...repairRecords[0],
[field]: `private-${field}`,
}),
).length;
const recordsMissingRequiredFields = [
...[...toolPlanProtocolAuditSafeFields].map((field) => {
const record = { ...normalizedProtocolRecord };
delete record[field];
return record;
}),
...[...toolPlanRepairAuditSafeFields].map((field) => {
const record = { ...repairRecords[0] };
delete record[field];
return record;
}),
];
const rejectedMissingAuditFieldCount = recordsMissingRequiredFields.filter(
(record) => !hasSafeToolPlanAuditPayload(record),
).length;
const wrongSlotAuditRecords = [
{ ...normalizedProtocolRecord, requestSlot: 'loop-8-repair-1' },
{ ...repairRecords[0], requestSlot: 'loop-0-repair-1' },
];
const rejectedWrongSlotCount = wrongSlotAuditRecords.filter(
(record) => !hasSafeToolPlanAuditPayload(record),
).length;
const rawIdentifierAuditFields = {
callId: syntheticProtocolCallId,
callIds: [syntheticProtocolCallId],
functionName: 'runtime_tool_file_read',
providerRequestId: 'private-provider-request-id',
responseId: syntheticProtocolResponseId,
};
const rejectedRawIdentifierFieldCount = Object.entries(
rawIdentifierAuditFields,
).filter(
([field, value]) =>
!hasSafeToolPlanAuditPayload({
...normalizedProtocolRecord,
[field]: value,
}),
).length;
const invalidHashOrCatalogAuditRecords = [
{
...normalizedProtocolRecord,
callIdSha256s: ['A'.repeat(64)],
},
{
...normalizedProtocolRecord,
responseIdSha256: null,
},
{
...normalizedProtocolRecord,
functionNames: ['private_uncatalogued_function'],
},
{
...repairRecords[0],
providerRequestIdSha256: '0'.repeat(63),
},
{
...repairRecords[0],
repairAttempt: 1,
requestSlot: 'loop-0-repair-1',
},
];
const rejectedInvalidHashOrCatalogCount =
invalidHashOrCatalogAuditRecords.filter(
(record) => !hasSafeToolPlanAuditPayload(record),
).length;
assert(
rejectedRawPayloadFieldCount === rawPayloadFields.length &&
rejectedMissingAuditFieldCount === recordsMissingRequiredFields.length &&
rejectedWrongSlotCount === wrongSlotAuditRecords.length &&
rejectedRawIdentifierFieldCount ===
Object.keys(rawIdentifierAuditFields).length &&
rejectedInvalidHashOrCatalogCount ===
invalidHashOrCatalogAuditRecords.length &&
hasSafeToolPlanAuditPayload(normalizedProtocolRecord) &&
!hasSafeToolPlanAuditPayload({
...normalizedProtocolRecord,
normalizationKinds: ['private-kind'],
}) &&
!hasSafeToolPlanAuditPayload({
...repairRecords[0],
protocolErrorKind: 'private-error',
}),
'agent-runtime-real-e2e-self-test-tool-plan-payload-boundary-invalid',
);
const repairReport = JSON.stringify(fullRepairEvidence);
const repairReportPrivateValueLeakCount = countExactSecrets(
Buffer.from(repairReport),
[
...Object.values(syntheticIdentity),
...repairRecords.flatMap((record) => [
record.responseFingerprint,
record.providerRequestIdSha256,
record.protocolErrorSha256,
record.responsePreviewSha256,
record.callIdSha256,
record.functionNameSha256,
]),
],
);
assert(
repairReportPrivateValueLeakCount === 0 &&
!/(agentId|taskId|sessionId|runId|source|requestSlot|loopIteration|Sha256)/u.test(
repairReport,
),
'agent-runtime-real-e2e-self-test-tool-plan-report-private-data-leak',
);
return {
status: 'PASS',
suite: 'agent-runtime-real-e2e-self-test',
providerUsed: false,
exactSecretCounts,
scopedPrivateOutputValidated,
recoveredRepairConfirmationLifecycleValidated: true,
modernRecoveredRepairConfirmationLifecycleValidated: true,
legacyRecoveredRepairConfirmationLifecycleValidated: true,
recoveredRepairConfirmationConflictRejected: true,
recoveredRepairConfirmationModeAndOrderValidated: true,
dynamicPrivateBodyCount: expectedPrivateValues.length,
evidenceMetadataExcluded: true,
genericBoundaryTermsExcluded: true,
mixedIsolatedGroupTopologyValidated: true,
mixedReadyJoinObservationValidated: true,
mixedObservedJoinClaimValidated: true,
mixedCrossGroupWriteScopesValidated: true,
mixedFollowupBeforeClaimOrderValidated: true,
legacySingleIsolatedGroupTopologyValidated: true,
mixedSuitePolicyIsolationValidated: true,
collaborationPolicySnapshotCaptured: true,
collaborationPolicySnapshotStable: true,
collaborationPolicySnapshotBindingCaptured: true,
collaborationPolicySnapshotBindingStable: true,
durableSnapshotEligibilityAndContractBindingValidated: true,
sourceEndpointAbsentLifecycleGuardValidated,
gameChatPlayableSuiteRegistered,
gameChatPlayablePackageCommandsRegistered,
gameChatPlayableModeValidated,
gameChatPlayableRequiredAgentsValidated,
autonomousPlayableSuiteRegistered,
autonomousPlayablePackageCommandsRegistered,
autonomousPlayableDedicatedPathValidated: true,
autonomousPlayableExactStdinValidated: true,
autonomousPlayablePartialCollectorPrivacyValidated,
toolPlanHandoffSuiteRegistered,
toolPlanHandoffPackageCommandsRegistered,
toolPlanHandoffSourceGuardRegistered,
toolPlanHandoffCleanupRegistered,
toolPlanHandoffPartialEvidenceRegistered: true,
toolPlanHandoffPlanProjectionValidated,
toolPlanHandoffEvidenceFieldsRegistered,
toolPlanHandoffUnknownResultBoundaryPreserved: true,
finalReplyFaultPrerequisiteValidated: true,
collaborationPolicyDriftFixtureValidated: true,
collaborationPolicyDriftStatusObserved: true,
duplicateCollaborationPolicySnapshotCount: syntheticSnapshotDuplicateCount,
duplicateCollaborationPolicySnapshotBindingCount:
syntheticSnapshotBindingDuplicateCount,
collaborationPolicySnapshotTamperRejected: syntheticSnapshotTamperRejected,
collaborationPolicySnapshotBindingTamperRejected:
syntheticSnapshotBindingTamperRejected,
collaborationPolicyPartialMissingEvidenceSafe:
syntheticMissingSnapshotSafe && syntheticMissingBindingSafe,
enospcFailureDiagnosticClassified: true,
chatSessionFailureEvidenceSchemaValidated: true,
toolPlanRepairCount: fullRepairEvidence.toolPlanRepairCount,
toolPlanRepairedLoopCount: fullRepairEvidence.toolPlanRepairedLoopCount,
toolPlanSecondRepairCount: fullRepairEvidence.toolPlanSecondRepairCount,
toolPlanRepairCountsByProtocolErrorKind:
fullRepairEvidence.toolPlanRepairCountsByProtocolErrorKind,
toolPlanRepairClassificationTotalMatched: true,
toolPlanFatalLocalRepairRejected: true,
toolPlanPersistedAuditEnvelopeAccepted: true,
toolPlanRawPayloadFieldRejectionCount: rejectedRawPayloadFieldCount,
toolPlanMissingAuditFieldRejectionCount: rejectedMissingAuditFieldCount,
toolPlanWrongSlotRejectionCount: rejectedWrongSlotCount,
toolPlanRawIdentifierFieldRejectionCount: rejectedRawIdentifierFieldCount,
toolPlanInvalidHashOrCatalogRejectionCount:
rejectedInvalidHashOrCatalogCount,
toolPlanRepairReportPrivateValueLeakCount:
repairReportPrivateValueLeakCount,
};
}