()
| 42 | } |
| 43 | |
| 44 | async function main() { |
| 45 | console.log('— fs round-trip —'); |
| 46 | const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'qodex-artifacts-')); |
| 47 | const write = async (p: string, c: string) => { await fs.mkdir(path.dirname(p), { recursive: true }); await fs.writeFile(p, c); }; |
| 48 | |
| 49 | const { manifest: m1 } = await createArtifact(tmp, { title: 'Landing Page', type: 'html', content: '<h1>v1</h1>' }, write); |
| 50 | check('create returns id', m1.id === 'landing-page'); |
| 51 | check('create writes v1 file', (await getArtifact(tmp, 'landing-page')).content === '<h1>v1</h1>'); |
| 52 | |
| 53 | const up = await updateArtifact(tmp, { id: 'landing-page', content: '<h1>v2</h1>', note: 'bigger' }, write); |
| 54 | check('update creates v2', up.version === 2); |
| 55 | check('current reads v2', (await getArtifact(tmp, 'landing-page')).content === '<h1>v2</h1>'); |
| 56 | check('v1 still retrievable', (await getArtifact(tmp, 'landing-page', 1)).content === '<h1>v1</h1>'); |
| 57 | |
| 58 | await rollbackArtifact(tmp, 'landing-page', 1, write); |
| 59 | check('rollback repoints current to v1', (await getArtifact(tmp, 'landing-page')).content === '<h1>v1</h1>'); |
| 60 | check('rollback keeps v2 in history', (await getArtifact(tmp, 'landing-page', 2)).content === '<h1>v2</h1>'); |
| 61 | |
| 62 | // duplicate title → unique id |
| 63 | const { manifest: dup } = await createArtifact(tmp, { title: 'Landing Page', type: 'html', content: 'x' }, write); |
| 64 | check('duplicate title gets -2 id', dup.id === 'landing-page-2'); |
| 65 | |
| 66 | const list = await listArtifacts(tmp); |
| 67 | check('list returns both artifacts', list.length === 2); |
| 68 | |
| 69 | // error paths |
| 70 | let threw = false; |
| 71 | try { await updateArtifact(tmp, { id: 'nope', content: 'x' }, write); } catch { threw = true; } |
| 72 | check('update of missing id throws', threw); |
| 73 | threw = false; |
| 74 | try { await getArtifact(tmp, 'landing-page', 99); } catch { threw = true; } |
| 75 | check('get of missing version throws', threw); |
| 76 | |
| 77 | await fs.rm(tmp, { recursive: true, force: true }); |
| 78 | console.log(`\n${passed} passed, ${failed} failed`); |
| 79 | process.exit(failed > 0 ? 1 : 0); |
| 80 | } |
| 81 | main(); |
no test coverage detected