* test: Bootstrapped sdk/ as TypeScript ESM package with full GSD-1 PLAN.… - "sdk/package.json" - "sdk/tsconfig.json" - "sdk/vitest.config.ts" - "sdk/src/types.ts" - "sdk/src/plan-parser.ts" - "sdk/src/plan-parser.test.ts" GSD-Task: S01/T01 * test: Implemented config reader and gsd-tools bridge with 25 unit tests… - "sdk/src/config.ts" - "sdk/src/config.test.ts" - "sdk/src/gsd-tools.ts" - "sdk/src/gsd-tools.test.ts" GSD-Task: S01/T02 * test: Built prompt-builder, session-runner, and GSD class — 85 total un… - "sdk/src/prompt-builder.ts" - "sdk/src/prompt-builder.test.ts" - "sdk/src/session-runner.ts" - "sdk/src/index.ts" - "sdk/src/types.ts" GSD-Task: S01/T03 * test: Created E2E integration test with fixtures proving full SDK pipel… - "sdk/src/e2e.integration.test.ts" - "sdk/test-fixtures/sample-plan.md" - "sdk/test-fixtures/.planning/config.json" - "sdk/test-fixtures/.planning/STATE.md" - "vitest.config.ts" - "tsconfig.json" GSD-Task: S01/T04 * test: Added PhaseType/GSDEventType enums, 16-variant GSDEvent union, GS… - "sdk/src/types.ts" - "sdk/src/event-stream.ts" - "sdk/src/logger.ts" - "sdk/src/event-stream.test.ts" - "sdk/src/logger.test.ts" GSD-Task: S02/T01 * test: Built ContextEngine for phase-aware context file resolution, getT… - "sdk/src/context-engine.ts" - "sdk/src/tool-scoping.ts" - "sdk/src/phase-prompt.ts" - "sdk/src/context-engine.test.ts" - "sdk/src/tool-scoping.test.ts" - "sdk/src/phase-prompt.test.ts" GSD-Task: S02/T02 * test: Wired event stream into session runner, added onEvent()/addTransp… - "sdk/src/session-runner.ts" - "sdk/src/index.ts" - "sdk/src/e2e.integration.test.ts" GSD-Task: S02/T03 * feat: Added PhaseStepType enum, PhaseOpInfo interface, phase lifecycle… - "sdk/src/types.ts" - "sdk/src/gsd-tools.ts" - "sdk/src/session-runner.ts" - "sdk/src/index.ts" - "sdk/src/phase-runner-types.test.ts" GSD-Task: S03/T01 * test: Implemented PhaseRunner state machine with 39 unit tests covering… - "sdk/src/phase-runner.ts" - "sdk/src/phase-runner.test.ts" GSD-Task: S03/T02 * test: Wired PhaseRunner into GSD.runPhase() public API with full re-exp… - "sdk/src/index.ts" - "sdk/src/phase-runner.integration.test.ts" - "sdk/src/phase-runner.ts" GSD-Task: S03/T03 * test: Expanded runVerifyStep with full gap closure cycle (plan → execut… - "sdk/src/types.ts" - "sdk/src/phase-runner.ts" - "sdk/src/phase-runner.test.ts" GSD-Task: S04/T02 * fix: Added 3 integration tests proving phasePlanIndex returns correct t… - "sdk/src/phase-runner.integration.test.ts" - "sdk/src/index.ts" GSD-Task: S04/T03 * test: Add milestone-level types, typed roadmapAnalyze(), GSD.run() orch… - "sdk/src/types.ts" - "sdk/src/gsd-tools.ts" - "sdk/src/index.ts" - "sdk/src/milestone-runner.test.ts" GSD-Task: S05/T01 * test: Added CLITransport (structured stdout log lines) and WSTransport… - "sdk/src/cli-transport.ts" - "sdk/src/cli-transport.test.ts" - "sdk/src/ws-transport.ts" - "sdk/src/ws-transport.test.ts" - "sdk/src/index.ts" - "sdk/package.json" GSD-Task: S05/T02 * test: Added gsd-sdk CLI entry point with argument parsing, bin field, p… - "sdk/src/cli.ts" - "sdk/src/cli.test.ts" - "sdk/package.json" GSD-Task: S05/T03 * feat: Add InitNewProjectInfo type, initNewProject()/configSet() GSDTool… - "sdk/src/types.ts" - "sdk/src/gsd-tools.ts" - "sdk/src/cli.ts" - "sdk/src/cli.test.ts" - "sdk/src/gsd-tools.test.ts" GSD-Task: S01/T01 * chore: Created InitRunner orchestrator with setup → config → PROJECT.md… - "sdk/src/init-runner.ts" - "sdk/src/types.ts" - "sdk/src/index.ts" GSD-Task: S01/T02 * test: Wired InitRunner into CLI main() for full gsd-sdk init dispatch a… - "sdk/src/cli.ts" - "sdk/src/init-runner.test.ts" - "sdk/src/cli.test.ts" GSD-Task: S01/T03 * test: Add PlanCheck step, AI self-discuss, and retryOnce wrapper to Pha… - "sdk/src/types.ts" - "sdk/src/phase-runner.ts" - "sdk/src/session-runner.ts" - "sdk/src/phase-runner.test.ts" - "sdk/src/phase-runner-types.test.ts" GSD-Task: S02/T01 * feat: Rewrite CLITransport with ANSI colors, phase banners, spawn indic… - "sdk/src/cli-transport.ts" - "sdk/src/cli-transport.test.ts" GSD-Task: S02/T02 * test: Add `gsd-sdk auto` command with autoMode config override, USAGE t… - "sdk/src/cli.ts" - "sdk/src/cli.test.ts" - "sdk/src/index.ts" - "sdk/src/types.ts" GSD-Task: S02/T03 * fix: CLI shebang + gsd-tools non-JSON output handling Three bugs found during first real gsd-sdk run: 1. cli.ts shebang was commented out — shell executed JS as bash, triggering ImageMagick's import command instead of Node 2. configSet() called exec() which JSON.parse()d the output, but gsd-tools config-set returns 'key=value' text, not JSON. Added execRaw() method for commands that return plain text. 3. Same JSON parse bug affected commit() (returns git SHA), stateLoad(), verifySummary(), initExecutePhase(), stateBeginPhase(), and phaseComplete(). All switched to execRaw(). Tests updated to match real gsd-tools output format (plain text instead of mocked JSON). 376/376 tests pass.
150 lines
4.8 KiB
TypeScript
150 lines
4.8 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { Writable } from 'node:stream';
|
|
import { GSDLogger } from './logger.js';
|
|
import type { LogEntry } from './logger.js';
|
|
import { PhaseType } from './types.js';
|
|
|
|
// ─── Test output capture ─────────────────────────────────────────────────────
|
|
|
|
class BufferStream extends Writable {
|
|
lines: string[] = [];
|
|
_write(chunk: Buffer, _encoding: string, callback: () => void): void {
|
|
const str = chunk.toString();
|
|
this.lines.push(...str.split('\n').filter(l => l.length > 0));
|
|
callback();
|
|
}
|
|
}
|
|
|
|
function parseLogEntry(line: string): LogEntry {
|
|
return JSON.parse(line) as LogEntry;
|
|
}
|
|
|
|
// ─── Tests ───────────────────────────────────────────────────────────────────
|
|
|
|
describe('GSDLogger', () => {
|
|
let output: BufferStream;
|
|
|
|
beforeEach(() => {
|
|
output = new BufferStream();
|
|
});
|
|
|
|
it('outputs valid JSON on each log call', () => {
|
|
const logger = new GSDLogger({ output, level: 'debug' });
|
|
logger.info('test message');
|
|
|
|
expect(output.lines).toHaveLength(1);
|
|
expect(() => JSON.parse(output.lines[0]!)).not.toThrow();
|
|
});
|
|
|
|
it('includes required fields: timestamp, level, message', () => {
|
|
const logger = new GSDLogger({ output, level: 'debug' });
|
|
logger.info('hello world');
|
|
|
|
const entry = parseLogEntry(output.lines[0]!);
|
|
expect(entry.timestamp).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
expect(entry.level).toBe('info');
|
|
expect(entry.message).toBe('hello world');
|
|
});
|
|
|
|
it('filters messages below minimum log level', () => {
|
|
const logger = new GSDLogger({ output, level: 'warn' });
|
|
|
|
logger.debug('should be dropped');
|
|
logger.info('should be dropped');
|
|
logger.warn('should appear');
|
|
logger.error('should appear');
|
|
|
|
expect(output.lines).toHaveLength(2);
|
|
expect(parseLogEntry(output.lines[0]!).level).toBe('warn');
|
|
expect(parseLogEntry(output.lines[1]!).level).toBe('error');
|
|
});
|
|
|
|
it('defaults to info level filtering', () => {
|
|
const logger = new GSDLogger({ output });
|
|
|
|
logger.debug('dropped');
|
|
logger.info('kept');
|
|
|
|
expect(output.lines).toHaveLength(1);
|
|
expect(parseLogEntry(output.lines[0]!).level).toBe('info');
|
|
});
|
|
|
|
it('writes to custom output stream', () => {
|
|
const customOutput = new BufferStream();
|
|
const logger = new GSDLogger({ output: customOutput, level: 'debug' });
|
|
logger.info('custom');
|
|
|
|
expect(customOutput.lines).toHaveLength(1);
|
|
expect(output.lines).toHaveLength(0);
|
|
});
|
|
|
|
it('includes phase, plan, and sessionId context when set', () => {
|
|
const logger = new GSDLogger({
|
|
output,
|
|
level: 'debug',
|
|
phase: PhaseType.Execute,
|
|
plan: 'test-plan',
|
|
sessionId: 'sess-123',
|
|
});
|
|
|
|
logger.info('context test');
|
|
|
|
const entry = parseLogEntry(output.lines[0]!);
|
|
expect(entry.phase).toBe('execute');
|
|
expect(entry.plan).toBe('test-plan');
|
|
expect(entry.sessionId).toBe('sess-123');
|
|
});
|
|
|
|
it('includes extra data when provided', () => {
|
|
const logger = new GSDLogger({ output, level: 'debug' });
|
|
logger.info('with data', { count: 42, tool: 'Bash' });
|
|
|
|
const entry = parseLogEntry(output.lines[0]!);
|
|
expect(entry.data).toEqual({ count: 42, tool: 'Bash' });
|
|
});
|
|
|
|
it('omits optional fields when not set', () => {
|
|
const logger = new GSDLogger({ output, level: 'debug' });
|
|
logger.info('minimal');
|
|
|
|
const entry = parseLogEntry(output.lines[0]!);
|
|
expect(entry.phase).toBeUndefined();
|
|
expect(entry.plan).toBeUndefined();
|
|
expect(entry.sessionId).toBeUndefined();
|
|
expect(entry.data).toBeUndefined();
|
|
});
|
|
|
|
it('supports runtime context updates via setters', () => {
|
|
const logger = new GSDLogger({ output, level: 'debug' });
|
|
|
|
logger.info('before');
|
|
logger.setPhase(PhaseType.Research);
|
|
logger.setPlan('my-plan');
|
|
logger.setSessionId('sess-456');
|
|
logger.info('after');
|
|
|
|
const before = parseLogEntry(output.lines[0]!);
|
|
const after = parseLogEntry(output.lines[1]!);
|
|
|
|
expect(before.phase).toBeUndefined();
|
|
expect(after.phase).toBe('research');
|
|
expect(after.plan).toBe('my-plan');
|
|
expect(after.sessionId).toBe('sess-456');
|
|
});
|
|
|
|
it('emits all four log levels correctly', () => {
|
|
const logger = new GSDLogger({ output, level: 'debug' });
|
|
|
|
logger.debug('d');
|
|
logger.info('i');
|
|
logger.warn('w');
|
|
logger.error('e');
|
|
|
|
expect(output.lines).toHaveLength(4);
|
|
expect(parseLogEntry(output.lines[0]!).level).toBe('debug');
|
|
expect(parseLogEntry(output.lines[1]!).level).toBe('info');
|
|
expect(parseLogEntry(output.lines[2]!).level).toBe('warn');
|
|
expect(parseLogEntry(output.lines[3]!).level).toBe('error');
|
|
});
|
|
});
|