style: sync paired workspace formatting fallout

This commit is contained in:
Eyejoker
2026-03-28 21:15:16 +09:00
parent e7f49d77da
commit 06b6326a9d
8 changed files with 426 additions and 353 deletions

View File

@@ -689,7 +689,9 @@ describe('paired task state', () => {
expect(getPairedTaskById('paired-task-2')?.status).toBe('review_ready'); expect(getPairedTaskById('paired-task-2')?.status).toBe('review_ready');
expect(getPairedExecutionById('paired-exec-2')?.status).toBe('running'); expect(getPairedExecutionById('paired-exec-2')?.status).toBe('running');
expect( expect(
listPairedWorkspacesForTask('paired-task-2').map((workspace) => workspace.workspace_dir), listPairedWorkspacesForTask('paired-task-2').map(
(workspace) => workspace.workspace_dir,
),
).toEqual(['/tmp/reviewer-v2']); ).toEqual(['/tmp/reviewer-v2']);
}); });
}); });

View File

@@ -1808,9 +1808,9 @@ export function createPairedTask(task: PairedTask): void {
} }
export function getPairedTaskById(id: string): PairedTask | undefined { export function getPairedTaskById(id: string): PairedTask | undefined {
return db return db.prepare('SELECT * FROM paired_tasks WHERE id = ?').get(id) as
.prepare('SELECT * FROM paired_tasks WHERE id = ?') | PairedTask
.get(id) as PairedTask | undefined; | undefined;
} }
export function getLatestOpenPairedTaskForChat( export function getLatestOpenPairedTaskForChat(
@@ -1905,9 +1905,9 @@ export function createPairedExecution(execution: PairedExecution): void {
export function getPairedExecutionById( export function getPairedExecutionById(
id: string, id: string,
): PairedExecution | undefined { ): PairedExecution | undefined {
return db return db.prepare('SELECT * FROM paired_executions WHERE id = ?').get(id) as
.prepare('SELECT * FROM paired_executions WHERE id = ?') | PairedExecution
.get(id) as PairedExecution | undefined; | undefined;
} }
export function updatePairedExecution( export function updatePairedExecution(

View File

@@ -310,8 +310,9 @@ describe('runAgentForGroup room memory', () => {
workDir: '/repo/canonical', workDir: '/repo/canonical',
}; };
vi.mocked(pairedExecutionContext.preparePairedExecutionContext).mockReturnValue( vi.mocked(
{ pairedExecutionContext.preparePairedExecutionContext,
).mockReturnValue({
task: { task: {
id: 'paired-task-1', id: 'paired-task-1',
chat_jid: 'group@test', chat_jid: 'group@test',
@@ -354,8 +355,7 @@ describe('runAgentForGroup room memory', () => {
EJCLAW_PAIRED_EXECUTION_ID: 'run-room-role:claude', EJCLAW_PAIRED_EXECUTION_ID: 'run-room-role:claude',
EJCLAW_PAIRED_ROLE: 'owner', EJCLAW_PAIRED_ROLE: 'owner',
}, },
}, });
);
await runAgentForGroup(makeDeps(), { await runAgentForGroup(makeDeps(), {
group, group,
@@ -403,8 +403,9 @@ describe('runAgentForGroup room memory', () => {
reason: null, reason: null,
explicit: false, explicit: false,
}); });
vi.mocked(pairedExecutionContext.preparePairedExecutionContext).mockReturnValue( vi.mocked(
{ pairedExecutionContext.preparePairedExecutionContext,
).mockReturnValue({
task: { task: {
id: 'paired-task-1', id: 'paired-task-1',
chat_jid: 'group@test', chat_jid: 'group@test',
@@ -439,8 +440,7 @@ describe('runAgentForGroup room memory', () => {
}, },
blockMessage: blockMessage:
'Review snapshot is not ready yet. Ask the owner to run /review-ready after preparing changes.', 'Review snapshot is not ready yet. Ask the owner to run /review-ready after preparing changes.',
}, });
);
const result = await runAgentForGroup(makeDeps(), { const result = await runAgentForGroup(makeDeps(), {
group, group,
@@ -449,7 +449,10 @@ describe('runAgentForGroup room memory', () => {
runId: 'run-blocked-reviewer', runId: 'run-blocked-reviewer',
onOutput: async (output) => { onOutput: async (output) => {
outputs.push({ outputs.push({
text: output.output && 'text' in output.output ? output.output.text : undefined, text:
output.output && 'text' in output.output
? output.output.text
: undefined,
result: output.result, result: output.result,
}); });
}, },

View File

@@ -281,7 +281,10 @@ export async function runAgentForGroup(
const outputText = getAgentOutputText(output); const outputText = getAgentOutputText(output);
if (typeof outputText === 'string' && outputText.length > 0) { if (typeof outputText === 'string' && outputText.length > 0) {
pairedExecutionSummary = outputText.slice(0, 500); pairedExecutionSummary = outputText.slice(0, 500);
} else if (typeof output.error === 'string' && output.error.length > 0) { } else if (
typeof output.error === 'string' &&
output.error.length > 0
) {
pairedExecutionSummary = output.error.slice(0, 500); pairedExecutionSummary = output.error.slice(0, 500);
} }
if ( if (
@@ -634,7 +637,11 @@ export async function runAgentForGroup(
} }
if (primaryAttempt.error) { if (primaryAttempt.error) {
if (canRotateToken && provider === 'claude' && !primaryAttempt.sawOutput) { if (
canRotateToken &&
provider === 'claude' &&
!primaryAttempt.sawOutput
) {
const errMsg = getErrorMessage(primaryAttempt.error); const errMsg = getErrorMessage(primaryAttempt.error);
const trigger = primaryAttempt.streamedTriggerReason const trigger = primaryAttempt.streamedTriggerReason
? { ? {
@@ -748,7 +755,11 @@ export async function runAgentForGroup(
} }
if (output.status === 'error') { if (output.status === 'error') {
if (canRotateToken && provider === 'claude' && !primaryAttempt.sawOutput) { if (
canRotateToken &&
provider === 'claude' &&
!primaryAttempt.sawOutput
) {
const trigger = primaryAttempt.streamedTriggerReason const trigger = primaryAttempt.streamedTriggerReason
? { ? {
shouldRetry: true, shouldRetry: true,

View File

@@ -236,9 +236,9 @@ describe('paired execution context', () => {
roomRoleContext: ownerContext, roomRoleContext: ownerContext,
}); });
expect(pairedWorkspaceManager.markPairedTaskReviewReady).toHaveBeenCalledWith( expect(
'task-1', pairedWorkspaceManager.markPairedTaskReviewReady,
); ).toHaveBeenCalledWith('task-1');
expect(result?.task.status).toBe('review_ready'); expect(result?.task.status).toBe('review_ready');
}); });
}); });

View File

@@ -100,7 +100,10 @@ describe('paired workspace manager', () => {
manager.markPairedTaskReviewReady('paired-task-1'); manager.markPairedTaskReviewReady('paired-task-1');
expect( expect(
fs.readFileSync(path.join(reviewerWorkspace.workspace_dir, 'README.md'), 'utf-8'), fs.readFileSync(
path.join(reviewerWorkspace.workspace_dir, 'README.md'),
'utf-8',
),
).toBe('owner modified\n'); ).toBe('owner modified\n');
expect( expect(
fs.readFileSync( fs.readFileSync(
@@ -109,14 +112,15 @@ describe('paired workspace manager', () => {
), ),
).toBe('review me\n'); ).toBe('review me\n');
expect( expect(
runGit(['config', '--local', '--get', 'remote.origin.pushurl'], reviewerWorkspace.workspace_dir), runGit(
['config', '--local', '--get', 'remote.origin.pushurl'],
reviewerWorkspace.workspace_dir,
),
).toBe('DISABLED_BY_EJCLAW'); ).toBe('DISABLED_BY_EJCLAW');
expect( expect(
runGit(['status', '--short'], reviewerWorkspace.workspace_dir), runGit(['status', '--short'], reviewerWorkspace.workspace_dir),
).toContain('M README.md'); ).toContain('M README.md');
expect( expect(db.getPairedTaskById('paired-task-1')?.status).toBe('review_ready');
db.getPairedTaskById('paired-task-1')?.status,
).toBe('review_ready');
expect( expect(
db.getPairedWorkspace('paired-task-1', 'reviewer')?.snapshot_refreshed_at, db.getPairedWorkspace('paired-task-1', 'reviewer')?.snapshot_refreshed_at,
).toBeTruthy(); ).toBeTruthy();
@@ -164,7 +168,10 @@ describe('paired workspace manager', () => {
manager.refreshReviewerSnapshotForPairedTask('paired-task-2'); manager.refreshReviewerSnapshotForPairedTask('paired-task-2');
fs.rmSync(path.join(ownerWorkspace.workspace_dir, 'remove.txt')); fs.rmSync(path.join(ownerWorkspace.workspace_dir, 'remove.txt'));
fs.writeFileSync(path.join(ownerWorkspace.workspace_dir, 'keep.txt'), 'updated\n'); fs.writeFileSync(
path.join(ownerWorkspace.workspace_dir, 'keep.txt'),
'updated\n',
);
const reviewerWorkspace = const reviewerWorkspace =
manager.refreshReviewerSnapshotForPairedTask('paired-task-2'); manager.refreshReviewerSnapshotForPairedTask('paired-task-2');
@@ -173,7 +180,10 @@ describe('paired workspace manager', () => {
fs.existsSync(path.join(reviewerWorkspace.workspace_dir, 'remove.txt')), fs.existsSync(path.join(reviewerWorkspace.workspace_dir, 'remove.txt')),
).toBe(false); ).toBe(false);
expect( expect(
fs.readFileSync(path.join(reviewerWorkspace.workspace_dir, 'keep.txt'), 'utf-8'), fs.readFileSync(
path.join(reviewerWorkspace.workspace_dir, 'keep.txt'),
'utf-8',
),
).toBe('updated\n'); ).toBe('updated\n');
expect( expect(
runGit(['status', '--short'], reviewerWorkspace.workspace_dir), runGit(['status', '--short'], reviewerWorkspace.workspace_dir),
@@ -189,10 +199,19 @@ describe('paired workspace manager', () => {
runGit(['init'], canonicalDir); runGit(['init'], canonicalDir);
runGit(['config', 'user.email', 'test@example.com'], canonicalDir); runGit(['config', 'user.email', 'test@example.com'], canonicalDir);
runGit(['config', 'user.name', 'EJClaw Test'], canonicalDir); runGit(['config', 'user.name', 'EJClaw Test'], canonicalDir);
fs.writeFileSync(path.join(canonicalDir, 'tracked.ts'), 'export const ok = 1;\n'); fs.writeFileSync(
fs.writeFileSync(path.join(canonicalDir, '.env.production'), 'TRACKED_SECRET=1\n'); path.join(canonicalDir, 'tracked.ts'),
'export const ok = 1;\n',
);
fs.writeFileSync(
path.join(canonicalDir, '.env.production'),
'TRACKED_SECRET=1\n',
);
fs.writeFileSync(path.join(canonicalDir, '.env.example'), 'EXAMPLE=1\n'); fs.writeFileSync(path.join(canonicalDir, '.env.example'), 'EXAMPLE=1\n');
runGit(['add', 'tracked.ts', '.env.production', '.env.example'], canonicalDir); runGit(
['add', 'tracked.ts', '.env.production', '.env.example'],
canonicalDir,
);
runGit(['commit', '-m', 'initial'], canonicalDir); runGit(['commit', '-m', 'initial'], canonicalDir);
const now = '2026-03-28T00:00:00.000Z'; const now = '2026-03-28T00:00:00.000Z';
@@ -223,20 +242,38 @@ describe('paired workspace manager', () => {
fs.mkdirSync(path.join(ownerWorkspace.workspace_dir, 'src'), { fs.mkdirSync(path.join(ownerWorkspace.workspace_dir, 'src'), {
recursive: true, recursive: true,
}); });
fs.mkdirSync(path.join(ownerWorkspace.workspace_dir, 'node_modules', '.cache'), { fs.mkdirSync(
path.join(ownerWorkspace.workspace_dir, 'node_modules', '.cache'),
{
recursive: true, recursive: true,
}); },
);
fs.mkdirSync(path.join(ownerWorkspace.workspace_dir, 'dist'), { fs.mkdirSync(path.join(ownerWorkspace.workspace_dir, 'dist'), {
recursive: true, recursive: true,
}); });
fs.mkdirSync(path.join(ownerWorkspace.workspace_dir, 'logs'), { fs.mkdirSync(path.join(ownerWorkspace.workspace_dir, 'logs'), {
recursive: true, recursive: true,
}); });
fs.writeFileSync(path.join(ownerWorkspace.workspace_dir, 'src', 'draft.ts'), 'export const draft = true;\n'); fs.writeFileSync(
fs.writeFileSync(path.join(ownerWorkspace.workspace_dir, '.env.local'), 'SECRET=1\n'); path.join(ownerWorkspace.workspace_dir, 'src', 'draft.ts'),
fs.writeFileSync(path.join(ownerWorkspace.workspace_dir, 'node_modules', '.cache', 'x'), 'cache\n'); 'export const draft = true;\n',
fs.writeFileSync(path.join(ownerWorkspace.workspace_dir, 'dist', 'bundle.js'), 'dist\n'); );
fs.writeFileSync(path.join(ownerWorkspace.workspace_dir, 'logs', 'debug.log'), 'log\n'); fs.writeFileSync(
path.join(ownerWorkspace.workspace_dir, '.env.local'),
'SECRET=1\n',
);
fs.writeFileSync(
path.join(ownerWorkspace.workspace_dir, 'node_modules', '.cache', 'x'),
'cache\n',
);
fs.writeFileSync(
path.join(ownerWorkspace.workspace_dir, 'dist', 'bundle.js'),
'dist\n',
);
fs.writeFileSync(
path.join(ownerWorkspace.workspace_dir, 'logs', 'debug.log'),
'log\n',
);
const reviewerWorkspace = const reviewerWorkspace =
manager.refreshReviewerSnapshotForPairedTask('paired-task-3'); manager.refreshReviewerSnapshotForPairedTask('paired-task-3');
@@ -248,7 +285,9 @@ describe('paired workspace manager', () => {
), ),
).toBe('export const draft = true;\n'); ).toBe('export const draft = true;\n');
expect( expect(
fs.existsSync(path.join(reviewerWorkspace.workspace_dir, '.env.production')), fs.existsSync(
path.join(reviewerWorkspace.workspace_dir, '.env.production'),
),
).toBe(false); ).toBe(false);
expect( expect(
fs.readFileSync( fs.readFileSync(
@@ -261,14 +300,23 @@ describe('paired workspace manager', () => {
).toBe(false); ).toBe(false);
expect( expect(
fs.existsSync( fs.existsSync(
path.join(reviewerWorkspace.workspace_dir, 'node_modules', '.cache', 'x'), path.join(
reviewerWorkspace.workspace_dir,
'node_modules',
'.cache',
'x',
),
), ),
).toBe(false); ).toBe(false);
expect( expect(
fs.existsSync(path.join(reviewerWorkspace.workspace_dir, 'dist', 'bundle.js')), fs.existsSync(
path.join(reviewerWorkspace.workspace_dir, 'dist', 'bundle.js'),
),
).toBe(false); ).toBe(false);
expect( expect(
fs.existsSync(path.join(reviewerWorkspace.workspace_dir, 'logs', 'debug.log')), fs.existsSync(
path.join(reviewerWorkspace.workspace_dir, 'logs', 'debug.log'),
),
).toBe(false); ).toBe(false);
}); });
}); });

View File

@@ -93,7 +93,10 @@ function runGit(args: string[], cwd?: string): string {
} }
function ensureGitRepository(repoDir: string): void { function ensureGitRepository(repoDir: string): void {
const insideWorkTree = runGit(['rev-parse', '--is-inside-work-tree'], repoDir); const insideWorkTree = runGit(
['rev-parse', '--is-inside-work-tree'],
repoDir,
);
if (insideWorkTree !== 'true') { if (insideWorkTree !== 'true') {
throw new Error(`Not a git repository: ${repoDir}`); throw new Error(`Not a git repository: ${repoDir}`);
} }
@@ -125,7 +128,9 @@ function listGitPaths(repoDir: string, args: string[]): string[] {
function isReviewerSnapshotDeniedPath(relativePath: string): boolean { function isReviewerSnapshotDeniedPath(relativePath: string): boolean {
const segments = relativePath.split(/[\\/]+/).filter(Boolean); const segments = relativePath.split(/[\\/]+/).filter(Boolean);
if (segments.some((segment) => REVIEWER_SNAPSHOT_DENY_SEGMENTS.has(segment))) { if (
segments.some((segment) => REVIEWER_SNAPSHOT_DENY_SEGMENTS.has(segment))
) {
return true; return true;
} }
@@ -237,7 +242,8 @@ function makeWorkspaceRecord(args: {
task_id: args.taskId, task_id: args.taskId,
role: args.role, role: args.role,
workspace_dir: args.workspaceDir, workspace_dir: args.workspaceDir,
snapshot_source_dir: args.snapshotSourceDir ?? existing?.snapshot_source_dir ?? null, snapshot_source_dir:
args.snapshotSourceDir ?? existing?.snapshot_source_dir ?? null,
status: 'ready', status: 'ready',
snapshot_refreshed_at: snapshot_refreshed_at:
args.snapshotRefreshedAt ?? existing?.snapshot_refreshed_at ?? null, args.snapshotRefreshedAt ?? existing?.snapshot_refreshed_at ?? null,
@@ -263,7 +269,10 @@ export function provisionOwnerWorkspaceForPairedTask(
if (!fs.existsSync(path.join(workspaceDir, '.git'))) { if (!fs.existsSync(path.join(workspaceDir, '.git'))) {
ensureCleanDirectory(parentDir); ensureCleanDirectory(parentDir);
runGit(['worktree', 'add', '--detach', workspaceDir, sourceRef], canonicalWorkDir); runGit(
['worktree', 'add', '--detach', workspaceDir, sourceRef],
canonicalWorkDir,
);
logger.info( logger.info(
{ taskId, workspaceDir, sourceRef }, { taskId, workspaceDir, sourceRef },
'Provisioned owner workspace for paired task', 'Provisioned owner workspace for paired task',

View File

@@ -187,9 +187,9 @@ describe('handleSessionCommand', () => {
it('handles authorized /review-ready without invoking the agent', async () => { it('handles authorized /review-ready without invoking the agent', async () => {
const deps = makeDeps({ const deps = makeDeps({
markReviewReady: vi.fn().mockResolvedValue( markReviewReady: vi
'Review snapshot updated.\n- Task: paired-task-1', .fn()
), .mockResolvedValue('Review snapshot updated.\n- Task: paired-task-1'),
}); });
const result = await handleSessionCommand({ const result = await handleSessionCommand({