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(getPairedExecutionById('paired-exec-2')?.status).toBe('running');
expect(
listPairedWorkspacesForTask('paired-task-2').map((workspace) => workspace.workspace_dir),
listPairedWorkspacesForTask('paired-task-2').map(
(workspace) => workspace.workspace_dir,
),
).toEqual(['/tmp/reviewer-v2']);
});
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -93,7 +93,10 @@ function runGit(args: string[], cwd?: string): string {
}
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') {
throw new Error(`Not a git repository: ${repoDir}`);
}
@@ -125,7 +128,9 @@ function listGitPaths(repoDir: string, args: string[]): string[] {
function isReviewerSnapshotDeniedPath(relativePath: string): 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;
}
@@ -237,7 +242,8 @@ function makeWorkspaceRecord(args: {
task_id: args.taskId,
role: args.role,
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',
snapshot_refreshed_at:
args.snapshotRefreshedAt ?? existing?.snapshot_refreshed_at ?? null,
@@ -263,7 +269,10 @@ export function provisionOwnerWorkspaceForPairedTask(
if (!fs.existsSync(path.join(workspaceDir, '.git'))) {
ensureCleanDirectory(parentDir);
runGit(['worktree', 'add', '--detach', workspaceDir, sourceRef], canonicalWorkDir);
runGit(
['worktree', 'add', '--detach', workspaceDir, sourceRef],
canonicalWorkDir,
);
logger.info(
{ taskId, workspaceDir, sourceRef },
'Provisioned owner workspace for paired task',

View File

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