import assert from 'node:assert/strict'; import { execFileSync } from 'node:child_process'; import { mkdtempSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import test from 'node:test'; import { observeBacklogActivity } from '../../src/observability/snapshot.mjs'; import '../../site/task-activity.js'; test('SCN-console-task-activity: managed Git observations distinguish stale owner requests from incomplete history without mutations', () => { const root = mkdtempSync(join(tmpdir(), 'torch-console-activity-')); const git = (args) => execFileSync('git', ['-C', root, ...args], { encoding: 'utf8', env: { ...process.env, GIT_AUTHOR_DATE: '2026-09-20T00:00:00Z', GIT_COMMITTER_DATE: '2026-09-20T00:00:00Z' } }).trim(); git(['init', '-b', 'main']); git(['config', 'user.email', 'test@example.invalid']); git(['config', 'user.name', 'Test']); writeFileSync(join(root, 'source.js'), 'export const value=1;'); git(['add', '.']); git(['commit', '-m', 'Initial source']); const head = git(['rev-parse', 'HEAD']); const tasks = [{ id: 'TASK-other', title: 'Implementation', state: 'ready', createdAt: '2026-09-21', history: [{ actorId: 'session-manager' }] }, { id: 'TASK-owner', title: '', state: 'blocked', createdAt: '2026-09-21', updatedAt: '2026-09-30', history: [{ actorId: 'owner' }] }]; const input = { repositoryRoot: root, tasks, config: { project: { main_branch: 'main' } }, manifest: { external: [] }, now: new Date('2026-09-30T00:00:00Z') }; const before = JSON.stringify(tasks); const full = observeBacklogActivity(input); assert.equal(full.available, true); assert.equal(full.complete, true); assert.equal(full.tasks[0].taskId, 'TASK-owner'); assert.equal(full.tasks[0].status, 'stale'); assert.equal(full.tasks[0].ageDays, 9, 'metadata edits must not hide neglected work'); const html = globalThis.TorchTaskActivity.render(full); assert.ok(html.indexOf('TASK-owner') < html.indexOf('TASK-other')); assert.match(html, /waiting may be expected/); assert.match(html, /<img src=x>/); assert.doesNotMatch(html, / { const input = { available: true, complete: false, truncated: true, unavailableBranches: ['