Skip to content

Commit a2df955

Browse files
author
Sorra
committed
chore: add integration docs and test-shims (WIP)
1 parent 4c93c13 commit a2df955

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

docs/INTEGRATION_TESTS.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Integration tests and shims
2+
===========================
3+
4+
This file documents the minimal integration-test shim and how to run the integration tests locally.
5+
6+
Shim
7+
----
8+
A lightweight Node shim is provided at test-shims/ob-ndjson-shim.js. It mimics the CLI by writing NDJSON progress events to stdout, optionally writing lines to stderr, and exiting with a configurable exit code.
9+
10+
Running integration tests
11+
-------------------------
12+
1. Ensure dependencies are installed: `npm install`.
13+
2. Run the integration tests: `npm run test:integration`.
14+
15+
Notes
16+
-----
17+
- The shim is invoked automatically when `OB_CLI_PATH` points at the shim file (the runner will spawn Node for `.js` paths).
18+
- The integration tests are intentionally small and hermetic; they do not require the real `ob` binary.

test-shims/ob-ndjson-shim.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
2+
// Minimal test shim that writes NDJSON progress events to stdout,
3+
// emits diagnostic lines to stderr optionally, and exits with the
4+
// requested code. This shim accepts arguments similar to the real CLI:
5+
// node test-shims/ob-ndjson-shim.js add --format ndjson <url> [--stderr <line>] [--exit <code>]
6+
7+
const { argv, exit, stderr, stdout } = process;
8+
9+
function usage() {
10+
console.error('Usage: node ob-ndjson-shim.js add --format ndjson <url> [--stderr <line>] [--exit <code>]');
11+
exit(2);
12+
}
13+
14+
async function main() {
15+
const args = argv.slice(2);
16+
if (args.length < 3) return usage();
17+
18+
const cmd = args[0];
19+
const fmtIdx = args.indexOf('--format');
20+
const fmt = fmtIdx >= 0 ? args[fmtIdx + 1] : undefined;
21+
const url = args[args.length - 1];
22+
23+
// parse optional flags
24+
let stderrLine = null;
25+
let exitCode = 0;
26+
for (let i = 0; i < args.length; i++) {
27+
if (args[i] === '--stderr') {
28+
stderrLine = args[i + 1];
29+
i++;
30+
} else if (args[i] === '--exit') {
31+
exitCode = parseInt(args[i + 1], 10) || 0;
32+
i++;
33+
}
34+
}
35+
36+
if (cmd !== 'add' || fmt !== 'ndjson') return usage();
37+
38+
// Emit a downloading event, then a completed event for the provided URL
39+
const now = new Date().toISOString();
40+
stdout.write(JSON.stringify({ phase: 'downloading', url, timestamp: now }) + '\n');
41+
// small delay to simulate streaming
42+
await new Promise((r) => setTimeout(r, 10));
43+
stdout.write(JSON.stringify({ phase: 'completed', url, title: 'Shim Title', id: 123, timestamp: new Date().toISOString() }) + '\n');
44+
45+
if (stderrLine) {
46+
stderr.write(stderrLine + '\n');
47+
}
48+
49+
exit(exitCode);
50+
}
51+
52+
main().catch((err) => {
53+
console.error('Shim error:', err);
54+
exit(1);
55+
});

0 commit comments

Comments
 (0)