macro-agent 0.1.8 → 0.1.10
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/CLAUDE.md +166 -33
- package/README.md +781 -131
- package/dist/acp/claude-code-replay.d.ts +11 -0
- package/dist/acp/claude-code-replay.d.ts.map +1 -0
- package/dist/acp/claude-code-replay.js +190 -0
- package/dist/acp/claude-code-replay.js.map +1 -0
- package/dist/acp/macro-agent.d.ts.map +1 -1
- package/dist/acp/macro-agent.js +155 -6
- package/dist/acp/macro-agent.js.map +1 -1
- package/dist/acp/types.d.ts +9 -0
- package/dist/acp/types.d.ts.map +1 -1
- package/dist/acp/types.js.map +1 -1
- package/dist/agent/agent-manager-v2.d.ts +21 -0
- package/dist/agent/agent-manager-v2.d.ts.map +1 -1
- package/dist/agent/agent-manager-v2.js +234 -43
- package/dist/agent/agent-manager-v2.js.map +1 -1
- package/dist/agent/agent-manager.d.ts +12 -0
- package/dist/agent/agent-manager.d.ts.map +1 -1
- package/dist/agent/agent-manager.js.map +1 -1
- package/dist/agent/types.d.ts +15 -2
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/boot-v2.d.ts +41 -0
- package/dist/boot-v2.d.ts.map +1 -1
- package/dist/boot-v2.js +16 -1
- package/dist/boot-v2.js.map +1 -1
- package/dist/cli/index.js +56 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cognitive/macro-agent-backend.d.ts.map +1 -1
- package/dist/cognitive/macro-agent-backend.js +40 -22
- package/dist/cognitive/macro-agent-backend.js.map +1 -1
- package/dist/integrations/skilltree.d.ts.map +1 -1
- package/dist/integrations/skilltree.js +1 -0
- package/dist/integrations/skilltree.js.map +1 -1
- package/dist/lifecycle/cleanup.d.ts +33 -2
- package/dist/lifecycle/cleanup.d.ts.map +1 -1
- package/dist/lifecycle/cleanup.js +28 -6
- package/dist/lifecycle/cleanup.js.map +1 -1
- package/dist/lifecycle/handlers-v2.d.ts +7 -0
- package/dist/lifecycle/handlers-v2.d.ts.map +1 -1
- package/dist/lifecycle/handlers-v2.js +28 -2
- package/dist/lifecycle/handlers-v2.js.map +1 -1
- package/dist/lifecycle/types.d.ts +11 -0
- package/dist/lifecycle/types.d.ts.map +1 -1
- package/dist/lifecycle/types.js.map +1 -1
- package/dist/map/acp-bridge.d.ts +9 -0
- package/dist/map/acp-bridge.d.ts.map +1 -1
- package/dist/map/acp-bridge.js +15 -2
- package/dist/map/acp-bridge.js.map +1 -1
- package/dist/map/cascade-bridge.d.ts +44 -0
- package/dist/map/cascade-bridge.d.ts.map +1 -0
- package/dist/map/cascade-bridge.js +257 -0
- package/dist/map/cascade-bridge.js.map +1 -0
- package/dist/map/lifecycle-bridge.d.ts +1 -1
- package/dist/map/lifecycle-bridge.d.ts.map +1 -1
- package/dist/map/lifecycle-bridge.js +58 -23
- package/dist/map/lifecycle-bridge.js.map +1 -1
- package/dist/map/server.d.ts.map +1 -1
- package/dist/map/server.js +47 -6
- package/dist/map/server.js.map +1 -1
- package/dist/map/sidecar.d.ts.map +1 -1
- package/dist/map/sidecar.js +33 -2
- package/dist/map/sidecar.js.map +1 -1
- package/dist/map/types.d.ts +20 -0
- package/dist/map/types.d.ts.map +1 -1
- package/dist/mcp/tools/done-v2.d.ts.map +1 -1
- package/dist/mcp/tools/done-v2.js +8 -0
- package/dist/mcp/tools/done-v2.js.map +1 -1
- package/dist/teams/team-manager-v2.d.ts.map +1 -1
- package/dist/teams/team-manager-v2.js +26 -0
- package/dist/teams/team-manager-v2.js.map +1 -1
- package/dist/teams/team-runtime-v2.d.ts.map +1 -1
- package/dist/teams/team-runtime-v2.js +16 -3
- package/dist/teams/team-runtime-v2.js.map +1 -1
- package/dist/workspace/config.d.ts +10 -10
- package/dist/workspace/config.d.ts.map +1 -1
- package/dist/workspace/config.js +4 -4
- package/dist/workspace/config.js.map +1 -1
- package/dist/workspace/git-cascade-adapter.d.ts +510 -0
- package/dist/workspace/git-cascade-adapter.d.ts.map +1 -0
- package/dist/workspace/git-cascade-adapter.js +908 -0
- package/dist/workspace/git-cascade-adapter.js.map +1 -0
- package/dist/workspace/index.d.ts +3 -3
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace/landing/direct-push.d.ts +20 -0
- package/dist/workspace/landing/direct-push.d.ts.map +1 -0
- package/dist/workspace/landing/direct-push.js +74 -0
- package/dist/workspace/landing/direct-push.js.map +1 -0
- package/dist/workspace/landing/index.d.ts +29 -0
- package/dist/workspace/landing/index.d.ts.map +1 -0
- package/dist/workspace/landing/index.js +37 -0
- package/dist/workspace/landing/index.js.map +1 -0
- package/dist/workspace/landing/merge-to-parent.d.ts +41 -0
- package/dist/workspace/landing/merge-to-parent.d.ts.map +1 -0
- package/dist/workspace/landing/merge-to-parent.js +185 -0
- package/dist/workspace/landing/merge-to-parent.js.map +1 -0
- package/dist/workspace/landing/optimistic-push.d.ts +16 -0
- package/dist/workspace/landing/optimistic-push.d.ts.map +1 -0
- package/dist/workspace/landing/optimistic-push.js +27 -0
- package/dist/workspace/landing/optimistic-push.js.map +1 -0
- package/dist/workspace/landing/queue-to-branch.d.ts +24 -0
- package/dist/workspace/landing/queue-to-branch.d.ts.map +1 -0
- package/dist/workspace/landing/queue-to-branch.js +79 -0
- package/dist/workspace/landing/queue-to-branch.js.map +1 -0
- package/dist/workspace/merge-queue/merge-queue.d.ts +10 -0
- package/dist/workspace/merge-queue/merge-queue.d.ts.map +1 -1
- package/dist/workspace/merge-queue/merge-queue.js +10 -0
- package/dist/workspace/merge-queue/merge-queue.js.map +1 -1
- package/dist/workspace/merge-queue/types.d.ts +16 -2
- package/dist/workspace/merge-queue/types.d.ts.map +1 -1
- package/dist/workspace/merge-queue/types.js +9 -0
- package/dist/workspace/merge-queue/types.js.map +1 -1
- package/dist/workspace/pool/types.d.ts +1 -0
- package/dist/workspace/pool/types.d.ts.map +1 -1
- package/dist/workspace/pool/worktree-pool.d.ts.map +1 -1
- package/dist/workspace/pool/worktree-pool.js +1 -0
- package/dist/workspace/pool/worktree-pool.js.map +1 -1
- package/dist/workspace/recovery/abandon.d.ts +15 -0
- package/dist/workspace/recovery/abandon.d.ts.map +1 -0
- package/dist/workspace/recovery/abandon.js +45 -0
- package/dist/workspace/recovery/abandon.js.map +1 -0
- package/dist/workspace/recovery/auto-resolve.d.ts +27 -0
- package/dist/workspace/recovery/auto-resolve.d.ts.map +1 -0
- package/dist/workspace/recovery/auto-resolve.js +99 -0
- package/dist/workspace/recovery/auto-resolve.js.map +1 -0
- package/dist/workspace/recovery/defer.d.ts +15 -0
- package/dist/workspace/recovery/defer.d.ts.map +1 -0
- package/dist/workspace/recovery/defer.js +16 -0
- package/dist/workspace/recovery/defer.js.map +1 -0
- package/dist/workspace/recovery/escalate.d.ts +16 -0
- package/dist/workspace/recovery/escalate.d.ts.map +1 -0
- package/dist/workspace/recovery/escalate.js +24 -0
- package/dist/workspace/recovery/escalate.js.map +1 -0
- package/dist/workspace/recovery/index.d.ts +32 -0
- package/dist/workspace/recovery/index.d.ts.map +1 -0
- package/dist/workspace/recovery/index.js +45 -0
- package/dist/workspace/recovery/index.js.map +1 -0
- package/dist/workspace/recovery/spawn-resolver.d.ts +45 -0
- package/dist/workspace/recovery/spawn-resolver.d.ts.map +1 -0
- package/dist/workspace/recovery/spawn-resolver.js +111 -0
- package/dist/workspace/recovery/spawn-resolver.js.map +1 -0
- package/dist/workspace/recovery/types.d.ts +63 -0
- package/dist/workspace/recovery/types.d.ts.map +1 -0
- package/dist/workspace/recovery/types.js +12 -0
- package/dist/workspace/recovery/types.js.map +1 -0
- package/dist/workspace/topology/index.d.ts +9 -0
- package/dist/workspace/topology/index.d.ts.map +1 -0
- package/dist/workspace/topology/index.js +8 -0
- package/dist/workspace/topology/index.js.map +1 -0
- package/dist/workspace/topology/no-workspace.d.ts +18 -0
- package/dist/workspace/topology/no-workspace.d.ts.map +1 -0
- package/dist/workspace/topology/no-workspace.js +25 -0
- package/dist/workspace/topology/no-workspace.js.map +1 -0
- package/dist/workspace/topology/types.d.ts +97 -0
- package/dist/workspace/topology/types.d.ts.map +1 -0
- package/dist/workspace/topology/types.js +20 -0
- package/dist/workspace/topology/types.js.map +1 -0
- package/dist/workspace/topology/yaml-driven.d.ts +69 -0
- package/dist/workspace/topology/yaml-driven.d.ts.map +1 -0
- package/dist/workspace/topology/yaml-driven.js +273 -0
- package/dist/workspace/topology/yaml-driven.js.map +1 -0
- package/dist/workspace/types-v3.d.ts +110 -0
- package/dist/workspace/types-v3.d.ts.map +1 -0
- package/dist/workspace/types-v3.js +20 -0
- package/dist/workspace/types-v3.js.map +1 -0
- package/dist/workspace/types.d.ts +145 -17
- package/dist/workspace/types.d.ts.map +1 -1
- package/dist/workspace/workspace-manager.d.ts +92 -13
- package/dist/workspace/workspace-manager.d.ts.map +1 -1
- package/dist/workspace/workspace-manager.js +373 -13
- package/dist/workspace/workspace-manager.js.map +1 -1
- package/dist/workspace/yaml-schema.d.ts +254 -0
- package/dist/workspace/yaml-schema.d.ts.map +1 -0
- package/dist/workspace/yaml-schema.js +170 -0
- package/dist/workspace/yaml-schema.js.map +1 -0
- package/docs/conflict-recovery.md +472 -0
- package/docs/git-cascade-integration-gaps.md +678 -0
- package/docs/workspace-interfaces.md +731 -0
- package/docs/workspace-redesign-plan.md +302 -0
- package/package.json +4 -4
- package/src/__tests__/e2e/auto-sync.e2e.test.ts +257 -0
- package/src/__tests__/e2e/cascade-rebase.e2e.test.ts +254 -0
- package/src/__tests__/e2e/cli-run.e2e.test.ts +167 -0
- package/src/__tests__/e2e/self-driving-v3.e2e.test.ts +197 -0
- package/src/__tests__/e2e/spawn-resolver.e2e.test.ts +200 -0
- package/src/__tests__/e2e/workspace-lifecycle.e2e.test.ts +30 -22
- package/src/__tests__/e2e/workspace-v3.e2e.test.ts +413 -0
- package/src/acp/__tests__/claude-code-replay.test.ts +225 -0
- package/src/acp/__tests__/macro-agent.test.ts +39 -1
- package/src/acp/claude-code-replay.ts +208 -0
- package/src/acp/macro-agent.ts +167 -9
- package/src/acp/types.ts +10 -0
- package/src/agent/__tests__/agent-manager-topology.test.ts +73 -0
- package/src/agent/__tests__/agent-manager-v2.test.ts +66 -0
- package/src/agent/__tests__/task-ref-resolution.test.ts +231 -0
- package/src/agent/agent-manager-v2.ts +293 -48
- package/src/agent/agent-manager.ts +14 -0
- package/src/agent/types.ts +16 -2
- package/src/boot-v2.ts +68 -1
- package/src/cli/index.ts +61 -0
- package/src/cognitive/macro-agent-backend.ts +45 -29
- package/src/integrations/skilltree.ts +1 -0
- package/src/lifecycle/cleanup.ts +52 -3
- package/src/lifecycle/handlers-v2.ts +40 -3
- package/src/lifecycle/types.ts +12 -0
- package/src/map/__tests__/cascade-bridge.test.ts +229 -0
- package/src/map/__tests__/lifecycle-bridge.test.ts +86 -10
- package/src/map/acp-bridge.ts +26 -3
- package/src/map/cascade-bridge.ts +301 -0
- package/src/map/lifecycle-bridge.ts +52 -17
- package/src/map/server.ts +47 -6
- package/src/map/sidecar.ts +31 -1
- package/src/map/types.ts +20 -0
- package/src/mcp/tools/done-v2.ts +9 -0
- package/src/teams/team-manager-v2.ts +37 -0
- package/src/teams/team-runtime-v2.ts +23 -3
- package/src/workspace/__tests__/{dataplane-adapter.test.ts → git-cascade-adapter.test.ts} +209 -14
- package/src/workspace/__tests__/self-driving-yaml.test.ts +114 -0
- package/src/workspace/__tests__/shared-worktree-refcount.test.ts +154 -0
- package/src/workspace/__tests__/standalone-mode.test.ts +118 -0
- package/src/workspace/__tests__/workspace-manager-v3.test.ts +245 -0
- package/src/workspace/__tests__/yaml-schema.test.ts +210 -0
- package/src/workspace/config.ts +11 -11
- package/src/workspace/git-cascade-adapter.ts +1186 -0
- package/src/workspace/index.ts +11 -11
- package/src/workspace/landing/__tests__/strategies.test.ts +142 -0
- package/src/workspace/landing/direct-push.ts +91 -0
- package/src/workspace/landing/index.ts +40 -0
- package/src/workspace/landing/merge-to-parent.ts +228 -0
- package/src/workspace/landing/optimistic-push.ts +36 -0
- package/src/workspace/landing/queue-to-branch.ts +108 -0
- package/src/workspace/merge-queue/merge-queue.ts +10 -0
- package/src/workspace/merge-queue/types.ts +16 -2
- package/src/workspace/pool/__tests__/worktree-pool.integration.test.ts +5 -5
- package/src/workspace/pool/types.ts +1 -0
- package/src/workspace/pool/worktree-pool.ts +1 -0
- package/src/workspace/recovery/__tests__/auto-resolve-integration.test.ts +127 -0
- package/src/workspace/recovery/__tests__/spawn-resolver.test.ts +139 -0
- package/src/workspace/recovery/__tests__/strategies.test.ts +145 -0
- package/src/workspace/recovery/abandon.ts +51 -0
- package/src/workspace/recovery/auto-resolve.ts +119 -0
- package/src/workspace/recovery/defer.ts +23 -0
- package/src/workspace/recovery/escalate.ts +30 -0
- package/src/workspace/recovery/index.ts +58 -0
- package/src/workspace/recovery/spawn-resolver.ts +145 -0
- package/src/workspace/recovery/types.ts +54 -0
- package/src/workspace/topology/__tests__/yaml-driven.test.ts +345 -0
- package/src/workspace/topology/index.ts +18 -0
- package/src/workspace/topology/no-workspace.ts +39 -0
- package/src/workspace/topology/types.ts +116 -0
- package/src/workspace/topology/yaml-driven.ts +316 -0
- package/src/workspace/types-v3.ts +155 -0
- package/src/workspace/types.ts +191 -20
- package/src/workspace/workspace-manager.ts +474 -19
- package/src/workspace/yaml-schema.ts +216 -0
- package/src/workspace/dataplane-adapter.ts +0 -546
|
@@ -506,12 +506,12 @@ export class TeamRuntimeV2 {
|
|
|
506
506
|
const capabilities = resolved.capabilities;
|
|
507
507
|
let streamId = options.streamId;
|
|
508
508
|
let streamConfig = options.streamConfig;
|
|
509
|
-
let
|
|
509
|
+
let gitCascadeTaskId = options.gitCascadeTaskId;
|
|
510
510
|
|
|
511
511
|
if (this.teamStreamId && capabilities) {
|
|
512
512
|
if (capabilities.includes(WORKSPACE_CAPABILITIES.WORKTREE)) {
|
|
513
513
|
streamId = streamId ?? this.teamStreamId;
|
|
514
|
-
|
|
514
|
+
gitCascadeTaskId = gitCascadeTaskId ?? `worker-${Date.now()}`;
|
|
515
515
|
} else if (capabilities.includes(WORKSPACE_CAPABILITIES.INTEGRATE)) {
|
|
516
516
|
streamId = streamId ?? this.teamStreamId;
|
|
517
517
|
}
|
|
@@ -521,7 +521,7 @@ export class TeamRuntimeV2 {
|
|
|
521
521
|
...options,
|
|
522
522
|
streamId,
|
|
523
523
|
streamConfig,
|
|
524
|
-
|
|
524
|
+
gitCascadeTaskId,
|
|
525
525
|
capabilities: capabilities ?? options.capabilities,
|
|
526
526
|
// Set team scope on all team agents
|
|
527
527
|
team_instance: options.team_instance ?? this.manifest.name,
|
|
@@ -846,6 +846,26 @@ Focus on correctness — your changes go live immediately.`);
|
|
|
846
846
|
const { workspaceManager } = this.services;
|
|
847
847
|
if (!workspaceManager || !this.integrationStrategy) return;
|
|
848
848
|
|
|
849
|
+
// V3 coexistence: if TeamManagerV2 has already wired a YamlDrivenTopology
|
|
850
|
+
// from `macro_agent.workspace`, that policy owns the team root stream.
|
|
851
|
+
// Don't create a second one via the legacy createIntegrationStream.
|
|
852
|
+
const hasV3Topology =
|
|
853
|
+
typeof (
|
|
854
|
+
this.services.agentManager as {
|
|
855
|
+
getTopologyPolicy?: () => unknown;
|
|
856
|
+
}
|
|
857
|
+
).getTopologyPolicy === 'function';
|
|
858
|
+
// AgentManager doesn't expose a getter today, so detect indirectly: a
|
|
859
|
+
// V3-wired team has already created a stream owned by `team:<name>`.
|
|
860
|
+
const existingTeamRoot = workspaceManager
|
|
861
|
+
.listStreams({ ownerId: `team:${this.manifest.name}` } as never)
|
|
862
|
+
.find((s: { name: string }) => s.name === this.manifest.name);
|
|
863
|
+
|
|
864
|
+
if (existingTeamRoot) {
|
|
865
|
+
this.teamStreamId = existingTeamRoot.id;
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
|
|
849
869
|
try {
|
|
850
870
|
this.teamStreamId = workspaceManager.createIntegrationStream(
|
|
851
871
|
rootAgentId,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* GitCascadeAdapter Tests
|
|
3
3
|
*
|
|
4
|
-
* Tests for the
|
|
4
|
+
* Tests for the git-cascade integration adapter.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
@@ -9,17 +9,17 @@ import * as fs from 'fs';
|
|
|
9
9
|
import * as path from 'path';
|
|
10
10
|
import * as os from 'os';
|
|
11
11
|
import { execSync } from 'child_process';
|
|
12
|
-
import {
|
|
12
|
+
import { GitCascadeAdapter, createGitCascadeAdapter } from '../git-cascade-adapter.js';
|
|
13
13
|
|
|
14
|
-
describe('
|
|
14
|
+
describe('GitCascadeAdapter', () => {
|
|
15
15
|
let tempDir: string;
|
|
16
16
|
let repoPath: string;
|
|
17
17
|
let dbPath: string;
|
|
18
|
-
let adapter:
|
|
18
|
+
let adapter: GitCascadeAdapter | null = null;
|
|
19
19
|
|
|
20
20
|
beforeEach(() => {
|
|
21
21
|
// Create temp directory
|
|
22
|
-
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), '
|
|
22
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'git-cascade-test-'));
|
|
23
23
|
repoPath = path.join(tempDir, 'repo');
|
|
24
24
|
dbPath = path.join(tempDir, 'test.db');
|
|
25
25
|
fs.mkdirSync(repoPath);
|
|
@@ -50,7 +50,7 @@ describe('DataplaneAdapter', () => {
|
|
|
50
50
|
|
|
51
51
|
describe('initialization', () => {
|
|
52
52
|
it('should create adapter with default config', () => {
|
|
53
|
-
adapter =
|
|
53
|
+
adapter = createGitCascadeAdapter({
|
|
54
54
|
enabled: true,
|
|
55
55
|
repoPath,
|
|
56
56
|
dbPath,
|
|
@@ -61,7 +61,7 @@ describe('DataplaneAdapter', () => {
|
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
it('should create adapter with custom table prefix', () => {
|
|
64
|
-
adapter =
|
|
64
|
+
adapter = createGitCascadeAdapter({
|
|
65
65
|
enabled: true,
|
|
66
66
|
repoPath,
|
|
67
67
|
dbPath,
|
|
@@ -73,7 +73,7 @@ describe('DataplaneAdapter', () => {
|
|
|
73
73
|
|
|
74
74
|
it('should use provided database path', () => {
|
|
75
75
|
const dbPath = path.join(tempDir, 'custom.db');
|
|
76
|
-
adapter =
|
|
76
|
+
adapter = createGitCascadeAdapter({
|
|
77
77
|
enabled: true,
|
|
78
78
|
repoPath,
|
|
79
79
|
dbPath,
|
|
@@ -85,7 +85,7 @@ describe('DataplaneAdapter', () => {
|
|
|
85
85
|
|
|
86
86
|
describe('stream operations', () => {
|
|
87
87
|
beforeEach(() => {
|
|
88
|
-
adapter =
|
|
88
|
+
adapter = createGitCascadeAdapter({
|
|
89
89
|
enabled: true,
|
|
90
90
|
repoPath,
|
|
91
91
|
dbPath,
|
|
@@ -138,7 +138,7 @@ describe('DataplaneAdapter', () => {
|
|
|
138
138
|
let streamId: string;
|
|
139
139
|
|
|
140
140
|
beforeEach(() => {
|
|
141
|
-
adapter =
|
|
141
|
+
adapter = createGitCascadeAdapter({
|
|
142
142
|
enabled: true,
|
|
143
143
|
repoPath,
|
|
144
144
|
dbPath,
|
|
@@ -197,7 +197,7 @@ describe('DataplaneAdapter', () => {
|
|
|
197
197
|
|
|
198
198
|
describe('health check', () => {
|
|
199
199
|
beforeEach(() => {
|
|
200
|
-
adapter =
|
|
200
|
+
adapter = createGitCascadeAdapter({
|
|
201
201
|
enabled: true,
|
|
202
202
|
repoPath,
|
|
203
203
|
dbPath,
|
|
@@ -217,7 +217,7 @@ describe('DataplaneAdapter', () => {
|
|
|
217
217
|
|
|
218
218
|
describe('event subscription', () => {
|
|
219
219
|
beforeEach(() => {
|
|
220
|
-
adapter =
|
|
220
|
+
adapter = createGitCascadeAdapter({
|
|
221
221
|
enabled: true,
|
|
222
222
|
repoPath,
|
|
223
223
|
dbPath,
|
|
@@ -252,7 +252,7 @@ describe('DataplaneAdapter', () => {
|
|
|
252
252
|
let worktreePath: string;
|
|
253
253
|
|
|
254
254
|
beforeEach(() => {
|
|
255
|
-
adapter =
|
|
255
|
+
adapter = createGitCascadeAdapter({
|
|
256
256
|
enabled: true,
|
|
257
257
|
repoPath,
|
|
258
258
|
dbPath,
|
|
@@ -365,4 +365,199 @@ describe('DataplaneAdapter', () => {
|
|
|
365
365
|
expect(checkpoints.length).toBeGreaterThanOrEqual(2);
|
|
366
366
|
});
|
|
367
367
|
});
|
|
368
|
+
|
|
369
|
+
// ───────────────────────────────────────────────────────────────────
|
|
370
|
+
// Phase 0 additive expansion — new surface coverage
|
|
371
|
+
// ───────────────────────────────────────────────────────────────────
|
|
372
|
+
|
|
373
|
+
describe('stream stacking (Phase 0)', () => {
|
|
374
|
+
beforeEach(() => {
|
|
375
|
+
adapter = createGitCascadeAdapter({
|
|
376
|
+
enabled: true,
|
|
377
|
+
repoPath,
|
|
378
|
+
dbPath,
|
|
379
|
+
skipRecovery: true,
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('forks a child stream off a parent', () => {
|
|
384
|
+
const parent = adapter!.createStream({ name: 'parent', agentId: 'agent-1' });
|
|
385
|
+
const child = adapter!.forkStream({
|
|
386
|
+
parentStreamId: parent,
|
|
387
|
+
name: 'child',
|
|
388
|
+
agentId: 'agent-2',
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
const childStream = adapter!.getStream(child);
|
|
392
|
+
expect(childStream?.parentStream).toBe(parent);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it('emits stream:forked on forkStream', () => {
|
|
396
|
+
const parent = adapter!.createStream({ name: 'parent', agentId: 'agent-1' });
|
|
397
|
+
const events: Array<{ type: string }> = [];
|
|
398
|
+
adapter!.onEvent((e) => events.push(e));
|
|
399
|
+
|
|
400
|
+
adapter!.forkStream({ parentStreamId: parent, name: 'child', agentId: 'agent-2' });
|
|
401
|
+
|
|
402
|
+
expect(events.some((e) => e.type === 'stream:forked')).toBe(true);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it('pauses and resumes a stream', () => {
|
|
406
|
+
const streamId = adapter!.createStream({ name: 'feat', agentId: 'a' });
|
|
407
|
+
adapter!.pauseStream(streamId, 'manual pause');
|
|
408
|
+
expect(adapter!.getStream(streamId)?.status).toBe('paused');
|
|
409
|
+
adapter!.resumeStream(streamId);
|
|
410
|
+
expect(adapter!.getStream(streamId)?.status).toBe('active');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it('tracks stream dependencies', () => {
|
|
414
|
+
const a = adapter!.createStream({ name: 'a', agentId: 'agent-1' });
|
|
415
|
+
const b = adapter!.createStream({ name: 'b', agentId: 'agent-1' });
|
|
416
|
+
adapter!.addDependency(b, a); // b depends on a
|
|
417
|
+
|
|
418
|
+
expect(adapter!.getDependencies(b)).toContain(a);
|
|
419
|
+
expect(adapter!.getDependents(a)).toContain(b);
|
|
420
|
+
|
|
421
|
+
adapter!.removeDependency(b, a);
|
|
422
|
+
expect(adapter!.getDependencies(b)).not.toContain(a);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it('returns stream hierarchy as tree', () => {
|
|
426
|
+
const root = adapter!.createStream({ name: 'root', agentId: 'a' });
|
|
427
|
+
const child = adapter!.forkStream({ parentStreamId: root, name: 'child', agentId: 'a' });
|
|
428
|
+
|
|
429
|
+
const hier = adapter!.getStreamHierarchy(root);
|
|
430
|
+
// Single root → StreamNode
|
|
431
|
+
const node = Array.isArray(hier) ? hier[0] : hier;
|
|
432
|
+
expect(node.stream.id).toBe(root);
|
|
433
|
+
expect(node.children.some((c) => c.stream.id === child)).toBe(true);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
describe('merge queue (Phase 0, delegates to git-cascade built-in)', () => {
|
|
438
|
+
let streamId: string;
|
|
439
|
+
beforeEach(() => {
|
|
440
|
+
adapter = createGitCascadeAdapter({
|
|
441
|
+
enabled: true,
|
|
442
|
+
repoPath,
|
|
443
|
+
dbPath,
|
|
444
|
+
skipRecovery: true,
|
|
445
|
+
});
|
|
446
|
+
streamId = adapter!.createStream({ name: 'feat-q', agentId: 'agent-1' });
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it('adds a stream to the queue and assigns a position', () => {
|
|
450
|
+
const entryId = adapter!.addToMergeQueue({ streamId, targetBranch: 'main', agentId: 'agent-1' });
|
|
451
|
+
expect(entryId).toBeDefined();
|
|
452
|
+
|
|
453
|
+
const pos = adapter!.getMergeQueuePosition(streamId, 'main');
|
|
454
|
+
expect(pos).not.toBeNull();
|
|
455
|
+
|
|
456
|
+
const entry = adapter!.getMergeQueueEntry(entryId);
|
|
457
|
+
expect(entry?.streamId).toBe(streamId);
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it('lists entries filtered by status', () => {
|
|
461
|
+
adapter!.addToMergeQueue({ streamId, targetBranch: 'main', agentId: 'agent-1' });
|
|
462
|
+
const pending = adapter!.listMergeQueue({ targetBranch: 'main', status: 'pending' });
|
|
463
|
+
expect(pending.length).toBeGreaterThan(0);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it('marks an entry ready and cancels it', () => {
|
|
467
|
+
const entryId = adapter!.addToMergeQueue({ streamId, targetBranch: 'main', agentId: 'agent-1' });
|
|
468
|
+
adapter!.markMergeQueueReady(entryId);
|
|
469
|
+
expect(adapter!.getMergeQueueEntry(entryId)?.status).toBe('ready');
|
|
470
|
+
|
|
471
|
+
adapter!.cancelMergeQueueEntry(entryId);
|
|
472
|
+
expect(adapter!.getMergeQueueEntry(entryId)?.status).toBe('cancelled');
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('emits mergeQueue:added / :ready / :cancelled events', () => {
|
|
476
|
+
const seen: string[] = [];
|
|
477
|
+
adapter!.onEvent((e) => seen.push(e.type));
|
|
478
|
+
|
|
479
|
+
const entryId = adapter!.addToMergeQueue({ streamId, targetBranch: 'main', agentId: 'agent-1' });
|
|
480
|
+
adapter!.markMergeQueueReady(entryId);
|
|
481
|
+
adapter!.cancelMergeQueueEntry(entryId);
|
|
482
|
+
|
|
483
|
+
expect(seen).toContain('mergeQueue:added');
|
|
484
|
+
expect(seen).toContain('mergeQueue:ready');
|
|
485
|
+
expect(seen).toContain('mergeQueue:cancelled');
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
describe('conflicts (Phase 0)', () => {
|
|
490
|
+
let streamId: string;
|
|
491
|
+
beforeEach(() => {
|
|
492
|
+
adapter = createGitCascadeAdapter({
|
|
493
|
+
enabled: true,
|
|
494
|
+
repoPath,
|
|
495
|
+
dbPath,
|
|
496
|
+
skipRecovery: true,
|
|
497
|
+
});
|
|
498
|
+
streamId = adapter!.createStream({ name: 'feat-c', agentId: 'agent-1' });
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
const dummyCommit = '0000000000000000000000000000000000000000';
|
|
502
|
+
|
|
503
|
+
it('creates and retrieves a conflict record', () => {
|
|
504
|
+
const id = adapter!.createConflict({
|
|
505
|
+
streamId,
|
|
506
|
+
conflictingCommit: dummyCommit,
|
|
507
|
+
targetCommit: dummyCommit,
|
|
508
|
+
conflictedFiles: ['a.ts', 'b.ts'],
|
|
509
|
+
});
|
|
510
|
+
const record = adapter!.getConflict(id);
|
|
511
|
+
expect(record?.streamId).toBe(streamId);
|
|
512
|
+
expect(record?.conflictedFiles).toEqual(['a.ts', 'b.ts']);
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
it('gets the active conflict for a stream', () => {
|
|
516
|
+
adapter!.createConflict({
|
|
517
|
+
streamId,
|
|
518
|
+
conflictingCommit: dummyCommit,
|
|
519
|
+
targetCommit: dummyCommit,
|
|
520
|
+
conflictedFiles: ['x.ts'],
|
|
521
|
+
});
|
|
522
|
+
const record = adapter!.getConflictForStream(streamId);
|
|
523
|
+
expect(record).not.toBeNull();
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
it('emits conflict:created event', () => {
|
|
527
|
+
const events: Array<{ type: string }> = [];
|
|
528
|
+
adapter!.onEvent((e) => events.push(e));
|
|
529
|
+
adapter!.createConflict({
|
|
530
|
+
streamId,
|
|
531
|
+
conflictingCommit: dummyCommit,
|
|
532
|
+
targetCommit: dummyCommit,
|
|
533
|
+
conflictedFiles: ['x.ts'],
|
|
534
|
+
});
|
|
535
|
+
expect(events.some((e) => e.type === 'conflict:created')).toBe(true);
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
describe('reconcile (Phase 0)', () => {
|
|
540
|
+
beforeEach(() => {
|
|
541
|
+
adapter = createGitCascadeAdapter({
|
|
542
|
+
enabled: true,
|
|
543
|
+
repoPath,
|
|
544
|
+
dbPath,
|
|
545
|
+
skipRecovery: true,
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it('checkStreamSync reports in-sync for a just-created stream', () => {
|
|
550
|
+
const streamId = adapter!.createStream({ name: 'feat-s', agentId: 'a' });
|
|
551
|
+
const status = adapter!.checkStreamSync(streamId);
|
|
552
|
+
expect(status).toBeDefined();
|
|
553
|
+
// Fresh stream should be in sync (no divergence yet)
|
|
554
|
+
expect(status.inSync).toBe(true);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it('reconcile runs without error on a healthy db', () => {
|
|
558
|
+
adapter!.createStream({ name: 'feat-r', agentId: 'a' });
|
|
559
|
+
const result = adapter!.reconcile({ dryRun: true });
|
|
560
|
+
expect(result).toBeDefined();
|
|
561
|
+
});
|
|
562
|
+
});
|
|
368
563
|
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression test: self-driving team.yaml parses cleanly under the V3
|
|
3
|
+
* workspace schema.
|
|
4
|
+
*
|
|
5
|
+
* Guards against YAML drift — if someone edits the team config in a way
|
|
6
|
+
* that breaks schema validation, this test fails loudly.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect } from 'vitest';
|
|
10
|
+
import * as fs from 'fs';
|
|
11
|
+
import * as path from 'path';
|
|
12
|
+
import * as yaml from 'js-yaml';
|
|
13
|
+
import {
|
|
14
|
+
parseTeamWorkspaceConfig,
|
|
15
|
+
extractWorkspaceConfig,
|
|
16
|
+
} from '../yaml-schema.js';
|
|
17
|
+
import { YamlDrivenTopology } from '../topology/yaml-driven.js';
|
|
18
|
+
import type { WorkspaceManager } from '../types.js';
|
|
19
|
+
import { vi } from 'vitest';
|
|
20
|
+
|
|
21
|
+
describe('self-driving team YAML (V3 migration)', () => {
|
|
22
|
+
const yamlPath = path.join(
|
|
23
|
+
process.cwd(),
|
|
24
|
+
'.multiagent/teams/self-driving/team.yaml'
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
it('exists on disk', () => {
|
|
28
|
+
expect(fs.existsSync(yamlPath)).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('parses and validates against TeamWorkspaceConfigSchema', () => {
|
|
32
|
+
const raw = fs.readFileSync(yamlPath, 'utf-8');
|
|
33
|
+
const manifest = yaml.load(raw) as { macro_agent?: Record<string, unknown> };
|
|
34
|
+
const config = extractWorkspaceConfig(manifest);
|
|
35
|
+
|
|
36
|
+
expect(config).not.toBeNull();
|
|
37
|
+
expect(config!.roles.planner).toBeDefined();
|
|
38
|
+
expect(config!.roles.grinder).toBeDefined();
|
|
39
|
+
expect(config!.roles.judge).toBeDefined();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('planner role maps to attach_to_team_root', () => {
|
|
43
|
+
const raw = fs.readFileSync(yamlPath, 'utf-8');
|
|
44
|
+
const manifest = yaml.load(raw) as { macro_agent?: Record<string, unknown> };
|
|
45
|
+
const config = extractWorkspaceConfig(manifest)!;
|
|
46
|
+
|
|
47
|
+
expect(config.roles.planner.workspace).toBe('attach_to_team_root');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('grinder forks from team root with direct_push landing', () => {
|
|
51
|
+
const raw = fs.readFileSync(yamlPath, 'utf-8');
|
|
52
|
+
const manifest = yaml.load(raw) as { macro_agent?: Record<string, unknown> };
|
|
53
|
+
const config = extractWorkspaceConfig(manifest)!;
|
|
54
|
+
|
|
55
|
+
expect(config.roles.grinder.workspace).toBe('new_stream');
|
|
56
|
+
expect(config.roles.grinder.stream_lineage).toBe('fork_from_team_root');
|
|
57
|
+
expect(config.roles.grinder.landing).toBe('direct_push');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('judge has no workspace (read-only role)', () => {
|
|
61
|
+
const raw = fs.readFileSync(yamlPath, 'utf-8');
|
|
62
|
+
const manifest = yaml.load(raw) as { macro_agent?: Record<string, unknown> };
|
|
63
|
+
const config = extractWorkspaceConfig(manifest)!;
|
|
64
|
+
|
|
65
|
+
expect(config.roles.judge.workspace).toBe('none');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('YamlDrivenTopology compiles the config into valid spawn decisions', async () => {
|
|
69
|
+
const raw = fs.readFileSync(yamlPath, 'utf-8');
|
|
70
|
+
const manifest = yaml.load(raw) as { macro_agent?: Record<string, unknown> };
|
|
71
|
+
const config = extractWorkspaceConfig(manifest)!;
|
|
72
|
+
|
|
73
|
+
const topology = new YamlDrivenTopology(config);
|
|
74
|
+
const mockWs = {
|
|
75
|
+
createStreamV3: vi.fn(() => 'team-stream-1'),
|
|
76
|
+
} as unknown as WorkspaceManager;
|
|
77
|
+
|
|
78
|
+
// Team start should create a team root (planner attaches to it)
|
|
79
|
+
await topology.onTeamStart({
|
|
80
|
+
teamName: 'self-driving',
|
|
81
|
+
teamInstanceId: 'sd-1',
|
|
82
|
+
workspaceConfig: config,
|
|
83
|
+
workspaceManager: mockWs,
|
|
84
|
+
});
|
|
85
|
+
expect(mockWs.createStreamV3).toHaveBeenCalled();
|
|
86
|
+
|
|
87
|
+
// Planner → attach-to-stream
|
|
88
|
+
const plannerDecision = await topology.onAgentSpawn({
|
|
89
|
+
agentId: 'agent-planner',
|
|
90
|
+
role: 'planner',
|
|
91
|
+
workspaceManager: mockWs,
|
|
92
|
+
});
|
|
93
|
+
expect(plannerDecision.kind).toBe('attach-to-stream');
|
|
94
|
+
|
|
95
|
+
// Grinder → new-stream (forked from team root)
|
|
96
|
+
const grinderDecision = await topology.onAgentSpawn({
|
|
97
|
+
agentId: 'agent-grinder-1',
|
|
98
|
+
role: 'grinder',
|
|
99
|
+
workspaceManager: mockWs,
|
|
100
|
+
});
|
|
101
|
+
expect(grinderDecision.kind).toBe('new-stream');
|
|
102
|
+
if (grinderDecision.kind === 'new-stream') {
|
|
103
|
+
expect(grinderDecision.streamSpec.parent).toBe('team-stream-1');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Judge → none
|
|
107
|
+
const judgeDecision = await topology.onAgentSpawn({
|
|
108
|
+
agentId: 'agent-judge',
|
|
109
|
+
role: 'judge',
|
|
110
|
+
workspaceManager: mockWs,
|
|
111
|
+
});
|
|
112
|
+
expect(judgeDecision.kind).toBe('none');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared worktree ref-counting tests (Gap 3 fix).
|
|
3
|
+
*
|
|
4
|
+
* Verifies the fixed deallocateWorkspace behavior for shared worktrees:
|
|
5
|
+
* - Sharer deallocation decrements ref-count without tearing down the worktree.
|
|
6
|
+
* - Owner deallocation with active sharers defers teardown (ownerDeparted flag).
|
|
7
|
+
* - Teardown fires when the last sharer leaves after owner departed.
|
|
8
|
+
* - Normal (non-shared) teardown is unchanged.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
12
|
+
import * as fs from 'fs';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
import * as os from 'os';
|
|
15
|
+
import { execSync } from 'child_process';
|
|
16
|
+
import { createGitCascadeAdapter, type GitCascadeAdapter } from '../git-cascade-adapter.js';
|
|
17
|
+
import {
|
|
18
|
+
DefaultWorkspaceManager,
|
|
19
|
+
createWorkspaceManagerWithAdapter,
|
|
20
|
+
} from '../workspace-manager.js';
|
|
21
|
+
|
|
22
|
+
describe('shared worktree ref-counting', () => {
|
|
23
|
+
let tempDir: string;
|
|
24
|
+
let repoPath: string;
|
|
25
|
+
let adapter: GitCascadeAdapter;
|
|
26
|
+
let manager: DefaultWorkspaceManager;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'refcount-'));
|
|
30
|
+
repoPath = path.join(tempDir, 'repo');
|
|
31
|
+
fs.mkdirSync(repoPath);
|
|
32
|
+
|
|
33
|
+
execSync('git init -b main', { cwd: repoPath, stdio: 'pipe' });
|
|
34
|
+
execSync('git config user.email "t@t.com"', { cwd: repoPath, stdio: 'pipe' });
|
|
35
|
+
execSync('git config user.name "T"', { cwd: repoPath, stdio: 'pipe' });
|
|
36
|
+
fs.writeFileSync(path.join(repoPath, 'README.md'), '# Test');
|
|
37
|
+
execSync('git add .', { cwd: repoPath, stdio: 'pipe' });
|
|
38
|
+
execSync('git commit -m "init"', { cwd: repoPath, stdio: 'pipe' });
|
|
39
|
+
|
|
40
|
+
adapter = createGitCascadeAdapter({
|
|
41
|
+
enabled: true,
|
|
42
|
+
repoPath,
|
|
43
|
+
dbPath: path.join(tempDir, 'db.sqlite'),
|
|
44
|
+
skipRecovery: true,
|
|
45
|
+
});
|
|
46
|
+
manager = createWorkspaceManagerWithAdapter(adapter, {
|
|
47
|
+
worktreeBaseDir: path.join(tempDir, 'worktrees'),
|
|
48
|
+
}) as DefaultWorkspaceManager;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
afterEach(() => {
|
|
52
|
+
manager.close();
|
|
53
|
+
adapter.close();
|
|
54
|
+
if (fs.existsSync(tempDir)) fs.rmSync(tempDir, { recursive: true, force: true });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('sharer deallocation decrements refs without touching the worktree', () => {
|
|
58
|
+
const streamId = manager.createStreamV3({ name: 's1', ownerId: 'owner-A' });
|
|
59
|
+
const owner = manager.allocateWorktree({ agentId: 'owner-A', streamId });
|
|
60
|
+
manager.allocateWorktree({ agentId: 'sharer-B', sharedWithAgent: 'owner-A' });
|
|
61
|
+
manager.allocateWorktree({ agentId: 'sharer-C', sharedWithAgent: 'owner-A' });
|
|
62
|
+
|
|
63
|
+
// Owner's worktree exists on disk
|
|
64
|
+
expect(fs.existsSync(owner.path)).toBe(true);
|
|
65
|
+
|
|
66
|
+
// Deallocate one sharer
|
|
67
|
+
manager.deallocateWorkspace('sharer-B');
|
|
68
|
+
expect(fs.existsSync(owner.path)).toBe(true);
|
|
69
|
+
|
|
70
|
+
// Owner's adapter record untouched
|
|
71
|
+
expect(adapter.getWorktree('owner-A')).not.toBeNull();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('owner deallocation with active sharers defers teardown', () => {
|
|
75
|
+
const streamId = manager.createStreamV3({ name: 's1', ownerId: 'owner-A' });
|
|
76
|
+
const owner = manager.allocateWorktree({ agentId: 'owner-A', streamId });
|
|
77
|
+
manager.allocateWorktree({ agentId: 'sharer-B', sharedWithAgent: 'owner-A' });
|
|
78
|
+
|
|
79
|
+
const events: Array<{ type: string }> = [];
|
|
80
|
+
manager.onEvent((e) => events.push(e));
|
|
81
|
+
|
|
82
|
+
manager.deallocateWorkspace('owner-A');
|
|
83
|
+
|
|
84
|
+
// Path still exists — teardown deferred
|
|
85
|
+
expect(fs.existsSync(owner.path)).toBe(true);
|
|
86
|
+
// git-cascade still thinks owner-A has a worktree (deferred state)
|
|
87
|
+
expect(adapter.getWorktree('owner-A')).not.toBeNull();
|
|
88
|
+
|
|
89
|
+
// Released event fired with kind=owner-departed
|
|
90
|
+
const released = events.find((e) => e.type === 'worktree:released');
|
|
91
|
+
expect(released).toBeDefined();
|
|
92
|
+
expect((released as { data?: { kind?: string } }).data?.kind).toBe('owner-departed');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('last sharer leaving after owner departed finalizes teardown', () => {
|
|
96
|
+
const streamId = manager.createStreamV3({ name: 's1', ownerId: 'owner-A' });
|
|
97
|
+
const owner = manager.allocateWorktree({ agentId: 'owner-A', streamId });
|
|
98
|
+
manager.allocateWorktree({ agentId: 'sharer-B', sharedWithAgent: 'owner-A' });
|
|
99
|
+
|
|
100
|
+
manager.deallocateWorkspace('owner-A');
|
|
101
|
+
// Still deferred
|
|
102
|
+
expect(fs.existsSync(owner.path)).toBe(true);
|
|
103
|
+
|
|
104
|
+
manager.deallocateWorkspace('sharer-B');
|
|
105
|
+
// Now actually torn down
|
|
106
|
+
expect(fs.existsSync(owner.path)).toBe(false);
|
|
107
|
+
expect(adapter.getWorktree('owner-A')).toBeNull();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('rejects allocation after owner departed with no sharers', () => {
|
|
111
|
+
const streamId = manager.createStreamV3({ name: 's1', ownerId: 'owner-A' });
|
|
112
|
+
manager.allocateWorktree({ agentId: 'owner-A', streamId });
|
|
113
|
+
manager.allocateWorktree({ agentId: 'sharer-B', sharedWithAgent: 'owner-A' });
|
|
114
|
+
|
|
115
|
+
manager.deallocateWorkspace('owner-A'); // owner departs (sharer-B still alive)
|
|
116
|
+
manager.deallocateWorkspace('sharer-B'); // last sharer leaves — torn down
|
|
117
|
+
|
|
118
|
+
// Now try to share again — owner is gone
|
|
119
|
+
expect(() =>
|
|
120
|
+
manager.allocateWorktree({ agentId: 'late-C', sharedWithAgent: 'owner-A' })
|
|
121
|
+
).toThrow();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('non-shared worktree teardown is unchanged', () => {
|
|
125
|
+
const streamId = manager.createStreamV3({ name: 's1', ownerId: 'lone-A' });
|
|
126
|
+
const wt = manager.allocateWorktree({ agentId: 'lone-A', streamId });
|
|
127
|
+
expect(fs.existsSync(wt.path)).toBe(true);
|
|
128
|
+
|
|
129
|
+
manager.deallocateWorkspace('lone-A');
|
|
130
|
+
expect(fs.existsSync(wt.path)).toBe(false);
|
|
131
|
+
expect(adapter.getWorktree('lone-A')).toBeNull();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('multiple sharers coexist; dealloc order does not matter', () => {
|
|
135
|
+
const streamId = manager.createStreamV3({ name: 's1', ownerId: 'owner-A' });
|
|
136
|
+
const owner = manager.allocateWorktree({ agentId: 'owner-A', streamId });
|
|
137
|
+
manager.allocateWorktree({ agentId: 'sharer-B', sharedWithAgent: 'owner-A' });
|
|
138
|
+
manager.allocateWorktree({ agentId: 'sharer-C', sharedWithAgent: 'owner-A' });
|
|
139
|
+
manager.allocateWorktree({ agentId: 'sharer-D', sharedWithAgent: 'owner-A' });
|
|
140
|
+
|
|
141
|
+
// Dealloc in a scrambled order: owner first, then sharers
|
|
142
|
+
manager.deallocateWorkspace('owner-A');
|
|
143
|
+
expect(fs.existsSync(owner.path)).toBe(true);
|
|
144
|
+
|
|
145
|
+
manager.deallocateWorkspace('sharer-C');
|
|
146
|
+
expect(fs.existsSync(owner.path)).toBe(true);
|
|
147
|
+
|
|
148
|
+
manager.deallocateWorkspace('sharer-D');
|
|
149
|
+
expect(fs.existsSync(owner.path)).toBe(true);
|
|
150
|
+
|
|
151
|
+
manager.deallocateWorkspace('sharer-B'); // last sharer
|
|
152
|
+
expect(fs.existsSync(owner.path)).toBe(false);
|
|
153
|
+
});
|
|
154
|
+
});
|