Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ Production npm publication is disabled until the release owner explicitly enable
Call CLI capabilities Commands, API capabilities Endpoints, and distributable agent instructions Playbooks. Write concrete copy and do not add em dashes to docs or comments.

For new or changed Commands, assess the candidate package smoke and read-only live smoke described in docs/development.md. Update useful coverage in the same PR and identify uncovered behavior explicitly. Keep the corresponding Factory regression case and runner source version coordinated; unit tests alone do not prove the deployed service contract.

## Test design

Follow [Factory's testing policy](https://github.com/DealMachine/dealmachine-factory/blob/master/guides/testing.md). Start with end-to-end behavior and reuse its existing test owner. For this repository, prefer executable request, route, protocol or integration tests that exercise real owned code. Visible app journeys use Factory's E2E workflow before implementation when possible. Add a unit test only when it is fast, deterministic and protects a distinct useful contract, such as API validation, money, permissions, parsing or serialization.

Avoid duplicate scenarios, mock-only behavior, private call counts and source checks that merely freeze an implementation. Keep independent public, security, storage and release contracts. A fix needs one regression that fails without the repair. During separately authorized cleanup, record the removed test's actual proof and its surviving owner, run the baseline, and obtain an independent preservation review. Ordinary feature work preserves existing coverage; this policy grants no unattended deletion authority.
42 changes: 1 addition & 41 deletions tests/lib/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vi.mock('node:child_process', () => ({
}),
}));

import { readConfig, writeConfig, deleteConfig, configExists, getConfigValue, setConfigValue } from '../../src/lib/config';
import { readConfig, writeConfig, deleteConfig, setConfigValue } from '../../src/lib/config';

const CONFIG_DIR = path.join('/tmp/test-home', '.dealmachine');
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
Expand Down Expand Up @@ -85,20 +85,6 @@ describe('CLI config', () => {
expect(writtenConfig.credentialStore).toBe('encrypted-file');
expect(writtenConfig.credentialFile).toBe(CREDENTIAL_FILE);
});

it('skips mkdir when directory exists', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
writeConfig(sampleConfig);
expect(fs.mkdirSync).not.toHaveBeenCalled();
});

it('falls back when the OS credential store is unavailable', () => {
vi.mocked(fs.existsSync).mockImplementation((file) => file === CONFIG_DIR);

writeConfig(sampleConfig);

expect(getWrittenConfig().credentialStore).toBe('encrypted-file');
});
});

describe('deleteConfig', () => {
Expand All @@ -114,32 +100,6 @@ describe('CLI config', () => {
});
});

describe('configExists', () => {
it('returns true when file exists', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
expect(configExists()).toBe(true);
});

it('returns false when file does not exist', () => {
vi.mocked(fs.existsSync).mockReturnValue(false);
expect(configExists()).toBe(false);
});
});

describe('getConfigValue', () => {
it('returns specific config value', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
vi.mocked(fs.readFileSync).mockReturnValue(JSON.stringify(sampleConfig));
expect(getConfigValue('apiKey')).toBe('dm_sk_live_test123');
expect(getConfigValue('organizationId')).toBe(7);
});

it('returns null when no config', () => {
vi.mocked(fs.existsSync).mockReturnValue(false);
expect(getConfigValue('apiKey')).toBeNull();
});
});

describe('setConfigValue', () => {
it('updates a single config value', () => {
vi.mocked(fs.existsSync).mockReturnValue(true);
Expand Down
15 changes: 1 addition & 14 deletions tests/lib/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ vi.mock('chalk', () => {
return { default: new Proxy({}, handler) };
});

import { truncate, printTable, printJson, printKeyValue } from '../../src/lib/output';
import { truncate, printTable, printJson } from '../../src/lib/output';

describe('output helpers', () => {
beforeEach(() => {
Expand Down Expand Up @@ -45,24 +45,11 @@ describe('output helpers', () => {
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('no results'));
});

it('prints header and rows', () => {
printTable([{ name: 'Alice', age: 30 }], ['name', 'age']);
// At least header + separator + 1 row = 3 calls
expect(vi.mocked(console.log).mock.calls.length).toBeGreaterThanOrEqual(3);
});

it('auto-detects columns from first row', () => {
printTable([{ x: 1, y: 2 }]);
const allOutput = vi.mocked(console.log).mock.calls.map(c => c[0]).join('\n');
expect(allOutput).toContain('x');
expect(allOutput).toContain('y');
});
});

describe('printKeyValue', () => {
it('prints key-value pairs', () => {
printKeyValue({ name: 'Test', count: 42 });
expect(vi.mocked(console.log).mock.calls.length).toBe(2);
});
});
});
Loading