@indigoai-us/hq-cli 5.15.0 → 5.17.0-sources-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +8 -4
- package/.github/workflows/publish.yml +8 -3
- package/dist/cli-version.d.ts +1 -0
- package/dist/cli-version.js +3 -2
- package/dist/commands/cloud-provision.d.ts +25 -0
- package/dist/commands/cloud-provision.js +75 -9
- package/dist/commands/groups.js +6 -6
- package/dist/commands/meetings.js +8 -8
- package/dist/commands/members.d.ts +4 -2
- package/dist/commands/members.js +30 -14
- package/dist/commands/signals.d.ts +24 -0
- package/dist/commands/signals.js +240 -0
- package/dist/commands/sources.d.ts +22 -0
- package/dist/commands/sources.js +250 -0
- package/dist/index.js +8 -2
- package/dist/utils/cognito-session.d.ts +10 -1
- package/dist/utils/cognito-session.js +18 -3
- package/package.json +5 -4
- package/scripts/smoke-sources-signals.sh +103 -0
- package/src/cli-version.ts +5 -1
- package/src/commands/cloud-provision.test.ts +27 -2
- package/src/commands/cloud-provision.ts +122 -7
- package/src/commands/groups.ts +4 -4
- package/src/commands/meetings.ts +6 -6
- package/src/commands/members.test.ts +56 -0
- package/src/commands/members.ts +44 -13
- package/src/commands/signals.ts +345 -0
- package/src/commands/sources.ts +356 -0
- package/src/index.ts +8 -0
- package/src/utils/cognito-session.test.ts +24 -1
- package/src/utils/cognito-session.ts +18 -0
- package/test/commands/signals.test.ts +200 -0
- package/test/commands/sources.test.ts +225 -0
- package/test/fixtures/signals/action_item/sample.md +16 -0
- package/test/fixtures/signals/summary/sample.md +12 -0
- package/test/fixtures/sources/meetings/sample.md +25 -0
- package/test/helpers/cli-runner.ts +150 -0
- package/test/helpers/s3-list-mock.ts +79 -0
- package/test/helpers/vault-service-mock.ts +160 -0
- package/test/sources-signals/smoke.test.ts +226 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cli-runner.ts — in-process Commander test harness.
|
|
3
|
+
*
|
|
4
|
+
* Builds a minimal Commander program and runs it with the given argv,
|
|
5
|
+
* capturing stdout/stderr without forking a child process.
|
|
6
|
+
*
|
|
7
|
+
* The program starts with only the core hq metadata (name, description,
|
|
8
|
+
* version). As new top-level command registrars are added to the CLI
|
|
9
|
+
* (US-006: sources, US-007: signals, etc.), import and register them here
|
|
10
|
+
* so tests that need the full command tree can use the same runner.
|
|
11
|
+
*
|
|
12
|
+
* NOTE: Some existing commands (pkg-install, pack-install) use semver deep
|
|
13
|
+
* subpath imports (semver/functions/satisfies.js) that are not resolvable in
|
|
14
|
+
* the pnpm test context. Those commands are excluded from the test program;
|
|
15
|
+
* add them here only if/when the semver resolution is fixed in devDeps.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* const { exitCode, stdout, stderr } = await runCli(['hq', '--help']);
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { Command } from "commander";
|
|
22
|
+
import { registerLoginCommand } from "../../src/commands/login.js";
|
|
23
|
+
import { registerLogoutCommand } from "../../src/commands/logout.js";
|
|
24
|
+
import { registerWhoamiCommand } from "../../src/commands/whoami.js";
|
|
25
|
+
import { registerSecretsCommand } from "../../src/commands/secrets.js";
|
|
26
|
+
import { registerGroupsCommand } from "../../src/commands/groups.js";
|
|
27
|
+
import { registerSourcesCommand } from "../../src/commands/sources.js";
|
|
28
|
+
import { registerSignalsCommand } from "../../src/commands/signals.js";
|
|
29
|
+
|
|
30
|
+
export interface CliRunResult {
|
|
31
|
+
exitCode: number;
|
|
32
|
+
stdout: string;
|
|
33
|
+
stderr: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Builds a test-only Commander program using exitOverride() so Commander
|
|
38
|
+
* throws CommanderError instead of calling process.exit().
|
|
39
|
+
*/
|
|
40
|
+
function buildProgram(): Command {
|
|
41
|
+
const program = new Command();
|
|
42
|
+
|
|
43
|
+
program
|
|
44
|
+
.name("hq")
|
|
45
|
+
.description("HQ management CLI — modules, packages, and cloud sync")
|
|
46
|
+
.version("0.0.0-test")
|
|
47
|
+
.exitOverride();
|
|
48
|
+
|
|
49
|
+
// Auth commands (no semver deep imports)
|
|
50
|
+
registerLoginCommand(program);
|
|
51
|
+
registerLogoutCommand(program);
|
|
52
|
+
registerWhoamiCommand(program);
|
|
53
|
+
|
|
54
|
+
// Secrets / groups (no semver deep imports)
|
|
55
|
+
registerSecretsCommand(program);
|
|
56
|
+
registerGroupsCommand(program);
|
|
57
|
+
|
|
58
|
+
// Sources read surface (US-006)
|
|
59
|
+
registerSourcesCommand(program);
|
|
60
|
+
|
|
61
|
+
// Signals read surface (US-007)
|
|
62
|
+
registerSignalsCommand(program);
|
|
63
|
+
|
|
64
|
+
return program;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Runs the hq CLI in-process with the given argv.
|
|
69
|
+
*
|
|
70
|
+
* stdout/stderr are intercepted for the duration of the call and restored
|
|
71
|
+
* afterward. Not safe to call concurrently (share process streams).
|
|
72
|
+
*/
|
|
73
|
+
export async function runCli(argv: string[]): Promise<CliRunResult> {
|
|
74
|
+
const stdoutChunks: string[] = [];
|
|
75
|
+
const stderrChunks: string[] = [];
|
|
76
|
+
let exitCode = 0;
|
|
77
|
+
|
|
78
|
+
const origStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
79
|
+
const origStderrWrite = process.stderr.write.bind(process.stderr);
|
|
80
|
+
const origExit = process.exit.bind(process);
|
|
81
|
+
|
|
82
|
+
const captureWrite =
|
|
83
|
+
(chunks: string[]) =>
|
|
84
|
+
(
|
|
85
|
+
chunk: string | Uint8Array,
|
|
86
|
+
encodingOrCb?: unknown,
|
|
87
|
+
cb?: unknown,
|
|
88
|
+
): boolean => {
|
|
89
|
+
chunks.push(typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf-8"));
|
|
90
|
+
if (typeof encodingOrCb === "function") (encodingOrCb as () => void)();
|
|
91
|
+
else if (typeof cb === "function") (cb as () => void)();
|
|
92
|
+
return true;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
(process.stdout as { write: unknown }).write = captureWrite(stdoutChunks);
|
|
96
|
+
(process.stderr as { write: unknown }).write = captureWrite(stderrChunks);
|
|
97
|
+
|
|
98
|
+
// Stub process.exit so action-handler exit(code) becomes a thrown error
|
|
99
|
+
// caught by parseAsync(). Otherwise it would tear down the vitest worker.
|
|
100
|
+
class ProcessExitError extends Error {
|
|
101
|
+
code: number;
|
|
102
|
+
constructor(code: number) {
|
|
103
|
+
super(`process.exit(${code})`);
|
|
104
|
+
this.name = "ProcessExitError";
|
|
105
|
+
this.code = code;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
(process as { exit: unknown }).exit = ((code?: number) => {
|
|
109
|
+
throw new ProcessExitError(code ?? 0);
|
|
110
|
+
}) as typeof process.exit;
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
const program = buildProgram();
|
|
114
|
+
// Commander's default strips 2 elements (node + script).
|
|
115
|
+
// Our argv convention is ['hq', ...userArgs], so strip the program name
|
|
116
|
+
// and use { from: 'user' } so Commander treats the rest as user args.
|
|
117
|
+
const userArgs = argv[0] === "hq" ? argv.slice(1) : argv;
|
|
118
|
+
await program.parseAsync(userArgs, { from: "user" });
|
|
119
|
+
exitCode = 0;
|
|
120
|
+
} catch (err: unknown) {
|
|
121
|
+
if (err instanceof ProcessExitError) {
|
|
122
|
+
// hq command threw via stubbed process.exit (withErrorHandling pattern).
|
|
123
|
+
// stderr was already written by the action handler.
|
|
124
|
+
exitCode = err.code;
|
|
125
|
+
} else if (err && typeof err === "object" && "code" in err) {
|
|
126
|
+
// Commander error from exitOverride()
|
|
127
|
+
const ce = err as { code: string; exitCode?: number };
|
|
128
|
+
if (ce.code === "commander.helpDisplayed" || ce.code === "commander.version") {
|
|
129
|
+
exitCode = 0;
|
|
130
|
+
} else {
|
|
131
|
+
exitCode = ce.exitCode ?? 1;
|
|
132
|
+
}
|
|
133
|
+
} else if (err instanceof Error) {
|
|
134
|
+
stderrChunks.push(err.message + "\n");
|
|
135
|
+
exitCode = 1;
|
|
136
|
+
} else {
|
|
137
|
+
exitCode = 1;
|
|
138
|
+
}
|
|
139
|
+
} finally {
|
|
140
|
+
process.stdout.write = origStdoutWrite;
|
|
141
|
+
process.stderr.write = origStderrWrite;
|
|
142
|
+
(process as { exit: unknown }).exit = origExit;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
exitCode,
|
|
147
|
+
stdout: stdoutChunks.join(""),
|
|
148
|
+
stderr: stderrChunks.join(""),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* s3-list-mock.ts — in-memory stub for @aws-sdk/client-s3 S3Client.
|
|
3
|
+
*
|
|
4
|
+
* Used by sources/signals tests that need ListObjectsV2 and GetObject behaviour
|
|
5
|
+
* without real AWS credentials or network I/O.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { S3Client } from "@aws-sdk/client-s3";
|
|
9
|
+
// NOTE: We intentionally do NOT use `instanceof ListObjectsV2Command` for
|
|
10
|
+
// dispatch. When this stub is consumed by code in a sibling package
|
|
11
|
+
// (@indigoai-us/hq-cloud's compiled dist), that code's @aws-sdk/client-s3
|
|
12
|
+
// resolution can produce a distinct constructor instance from the one we
|
|
13
|
+
// import here, breaking instanceof. Dispatching on `command.constructor.name`
|
|
14
|
+
// is identity-free and works across package boundaries.
|
|
15
|
+
|
|
16
|
+
export interface MockEntry {
|
|
17
|
+
/** S3 object key (e.g. "sources/meetings/abc.md") */
|
|
18
|
+
key: string;
|
|
19
|
+
/** Full file content as UTF-8 string */
|
|
20
|
+
content: string;
|
|
21
|
+
/** Optional override; defaults to 2026-01-01T00:00:00Z */
|
|
22
|
+
lastModified?: Date;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface MockS3Options {
|
|
26
|
+
entries: MockEntry[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns a stub S3Client whose `send` method handles:
|
|
31
|
+
* - ListObjectsV2Command — filters entries by Prefix, no pagination
|
|
32
|
+
* - GetObjectCommand — returns a streaming Body for the matching entry
|
|
33
|
+
*
|
|
34
|
+
* Throws `NoSuchKey` (matching AWS SDK error shape) for GetObject misses.
|
|
35
|
+
*/
|
|
36
|
+
export function mockS3WithEntries(opts: MockS3Options): S3Client {
|
|
37
|
+
const { entries } = opts;
|
|
38
|
+
const defaultDate = new Date("2026-01-01T00:00:00Z");
|
|
39
|
+
|
|
40
|
+
async function send(command: unknown): Promise<unknown> {
|
|
41
|
+
const cmdName = (command as { constructor?: { name?: string } }).constructor?.name ?? "";
|
|
42
|
+
|
|
43
|
+
if (cmdName === "ListObjectsV2Command") {
|
|
44
|
+
const { Prefix } = (command as { input: { Bucket: string; Prefix?: string } }).input;
|
|
45
|
+
const prefix = Prefix ?? "";
|
|
46
|
+
const filtered = entries.filter((e) => e.key.startsWith(prefix));
|
|
47
|
+
return {
|
|
48
|
+
Contents: filtered.map((e) => ({
|
|
49
|
+
Key: e.key,
|
|
50
|
+
Size: Buffer.byteLength(e.content, "utf-8"),
|
|
51
|
+
LastModified: e.lastModified ?? defaultDate,
|
|
52
|
+
ETag: `"mock-etag"`,
|
|
53
|
+
})),
|
|
54
|
+
IsTruncated: false,
|
|
55
|
+
NextContinuationToken: undefined,
|
|
56
|
+
$metadata: {},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (cmdName === "GetObjectCommand") {
|
|
61
|
+
const { Key } = (command as { input: { Bucket: string; Key: string } }).input;
|
|
62
|
+
const entry = entries.find((e) => e.key === Key);
|
|
63
|
+
if (!entry) {
|
|
64
|
+
const err = new Error(`The specified key does not exist: ${Key}`);
|
|
65
|
+
(err as NodeJS.ErrnoException).name = "NoSuchKey";
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
const content = entry.content;
|
|
69
|
+
async function* bodyStream(): AsyncIterable<Uint8Array> {
|
|
70
|
+
yield Buffer.from(content, "utf-8");
|
|
71
|
+
}
|
|
72
|
+
return { Body: bodyStream(), $metadata: {} };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
throw new Error(`mockS3WithEntries: unhandled command type "${cmdName || "unknown"}"`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { send } as unknown as S3Client;
|
|
79
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vault-service-mock.ts — fetch stub for vault-service HTTP endpoints.
|
|
3
|
+
*
|
|
4
|
+
* Intercepts globalThis.fetch and handles the subset of vault-service routes
|
|
5
|
+
* needed by entity-resolver and STS tests. Returns the original fetch restore
|
|
6
|
+
* function so callers can clean up in afterEach/finally.
|
|
7
|
+
*
|
|
8
|
+
* Handled endpoints (URL path suffixes):
|
|
9
|
+
* GET .../membership/me returns { memberships: [...] }
|
|
10
|
+
* GET .../entity/by-slug/{type}/{slug} returns { entity: {...} }
|
|
11
|
+
* POST .../entities/{uid}/sts returns { credentials, expiresAt, bucketName, region }
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { Membership, EntityInfo } from "@indigoai-us/hq-cloud";
|
|
15
|
+
|
|
16
|
+
export interface MockEntity {
|
|
17
|
+
/** Entity UID (e.g. "cmp_indigo_001") */
|
|
18
|
+
uid: string;
|
|
19
|
+
/** Human-readable stable slug (e.g. "indigo", "personal") */
|
|
20
|
+
slug: string;
|
|
21
|
+
/** S3 bucket name for this entity */
|
|
22
|
+
bucketName: string;
|
|
23
|
+
/** AWS region; defaults to "us-east-1" */
|
|
24
|
+
region?: string;
|
|
25
|
+
/** Entity role in this membership; defaults to "owner" */
|
|
26
|
+
role?: "owner" | "admin" | "member" | "guest";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface MockStsCredentials {
|
|
30
|
+
accessKeyId: string;
|
|
31
|
+
secretAccessKey: string;
|
|
32
|
+
sessionToken: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface MockVaultOptions {
|
|
36
|
+
entities: MockEntity[];
|
|
37
|
+
/** STS credentials returned for every POST /entities/{uid}/sts; defaults to test creds */
|
|
38
|
+
stsCredentials?: MockStsCredentials;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const DEFAULT_STS: MockStsCredentials = {
|
|
42
|
+
accessKeyId: "ASIAMOCK000000000001",
|
|
43
|
+
secretAccessKey: "mockSecretAccessKey",
|
|
44
|
+
sessionToken: "mockSessionToken",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Installs a fetch stub for vault-service endpoints.
|
|
49
|
+
*
|
|
50
|
+
* @returns A restore function — call it in afterEach to un-install the stub.
|
|
51
|
+
*/
|
|
52
|
+
export function mockVaultService(opts: MockVaultOptions): () => void {
|
|
53
|
+
const { entities, stsCredentials = DEFAULT_STS } = opts;
|
|
54
|
+
const originalFetch = globalThis.fetch as typeof fetch | undefined;
|
|
55
|
+
|
|
56
|
+
globalThis.fetch = async (
|
|
57
|
+
input: RequestInfo | URL,
|
|
58
|
+
init?: RequestInit,
|
|
59
|
+
): Promise<Response> => {
|
|
60
|
+
const url =
|
|
61
|
+
typeof input === "string"
|
|
62
|
+
? input
|
|
63
|
+
: input instanceof URL
|
|
64
|
+
? input.toString()
|
|
65
|
+
: (input as Request).url;
|
|
66
|
+
const method =
|
|
67
|
+
(init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
68
|
+
|
|
69
|
+
// GET /membership/me
|
|
70
|
+
if (method === "GET" && /\/membership\/me(\?.*)?$/.test(url)) {
|
|
71
|
+
const memberships: Partial<Membership>[] = entities.map((e) => ({
|
|
72
|
+
membershipKey: `mbr_${e.uid}`,
|
|
73
|
+
personUid: "prs_test_person_001",
|
|
74
|
+
companyUid: e.uid,
|
|
75
|
+
role: e.role ?? "owner",
|
|
76
|
+
status: "active",
|
|
77
|
+
invitedBy: "system",
|
|
78
|
+
invitedAt: "2026-01-01T00:00:00Z",
|
|
79
|
+
createdAt: "2026-01-01T00:00:00Z",
|
|
80
|
+
updatedAt: "2026-01-01T00:00:00Z",
|
|
81
|
+
}));
|
|
82
|
+
return json({ memberships });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// GET /entity/by-slug/{type}/{slug}
|
|
86
|
+
const bySlugMatch = /\/entity\/by-slug\/[^/]+\/([^/?]+)/.exec(url);
|
|
87
|
+
if (method === "GET" && bySlugMatch) {
|
|
88
|
+
const slug = decodeURIComponent(bySlugMatch[1]);
|
|
89
|
+
const entity = entities.find((e) => e.slug === slug);
|
|
90
|
+
if (!entity) {
|
|
91
|
+
return json({ error: "Not found" }, 404);
|
|
92
|
+
}
|
|
93
|
+
const info: Partial<EntityInfo> = {
|
|
94
|
+
uid: entity.uid,
|
|
95
|
+
slug: entity.slug,
|
|
96
|
+
type: "company",
|
|
97
|
+
name: entity.slug,
|
|
98
|
+
bucketName: entity.bucketName,
|
|
99
|
+
status: "active",
|
|
100
|
+
};
|
|
101
|
+
return json({ entity: info });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// GET /entity/{uid} (direct UID lookup — used by entity-resolver)
|
|
105
|
+
const entityUidMatch = /\/entity\/([^/?]+)$/.exec(url);
|
|
106
|
+
if (method === "GET" && entityUidMatch) {
|
|
107
|
+
const uid = decodeURIComponent(entityUidMatch[1]);
|
|
108
|
+
const entity = entities.find((e) => e.uid === uid);
|
|
109
|
+
if (!entity) {
|
|
110
|
+
return json({ error: `Entity '${uid}' not found` }, 404);
|
|
111
|
+
}
|
|
112
|
+
const info: Partial<EntityInfo> = {
|
|
113
|
+
uid: entity.uid,
|
|
114
|
+
slug: entity.slug,
|
|
115
|
+
type: "company",
|
|
116
|
+
name: entity.slug,
|
|
117
|
+
bucketName: entity.bucketName,
|
|
118
|
+
status: "active",
|
|
119
|
+
};
|
|
120
|
+
return json({ entity: info });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// POST /entities/{uid}/sts
|
|
124
|
+
const entityStsMatch = /\/entities\/([^/]+)\/sts/.exec(url);
|
|
125
|
+
if (method === "POST" && entityStsMatch) {
|
|
126
|
+
const uid = decodeURIComponent(entityStsMatch[1]);
|
|
127
|
+
const entity = entities.find((e) => e.uid === uid);
|
|
128
|
+
if (!entity) {
|
|
129
|
+
return json({ error: `Entity '${uid}' not found` }, 404);
|
|
130
|
+
}
|
|
131
|
+
return json({
|
|
132
|
+
credentials: stsCredentials,
|
|
133
|
+
expiresAt: new Date(Date.now() + 3600 * 1000).toISOString(),
|
|
134
|
+
bucketName: entity.bucketName,
|
|
135
|
+
region: entity.region ?? "us-east-1",
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Unhandled — pass through if original fetch exists, else 500
|
|
140
|
+
if (originalFetch) {
|
|
141
|
+
return originalFetch(input, init);
|
|
142
|
+
}
|
|
143
|
+
return json({ error: `mockVaultService: unhandled request ${method} ${url}` }, 500);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return () => {
|
|
147
|
+
if (originalFetch) {
|
|
148
|
+
globalThis.fetch = originalFetch;
|
|
149
|
+
} else {
|
|
150
|
+
delete (globalThis as Record<string, unknown>).fetch;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function json(body: unknown, status = 200): Response {
|
|
156
|
+
return new Response(JSON.stringify(body), {
|
|
157
|
+
status,
|
|
158
|
+
headers: { "Content-Type": "application/json" },
|
|
159
|
+
});
|
|
160
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* smoke.test.ts — Phase 0 infrastructure smoke test (US-001).
|
|
3
|
+
*
|
|
4
|
+
* Validates that:
|
|
5
|
+
* 1. The fixture files exist and have the expected frontmatter shape.
|
|
6
|
+
* 2. mockS3WithEntries lists and retrieves entries with full round-trip fidelity.
|
|
7
|
+
* 3. mockVaultService intercepts /membership/me and /entities/{uid}/sts correctly.
|
|
8
|
+
* 4. runCli(['hq', '--help']) exits 0 (basic wiring check).
|
|
9
|
+
*
|
|
10
|
+
* Note: assertions about 'sources'/'signals' appearing in `hq --help` are
|
|
11
|
+
* intentionally absent here — those land when US-006/US-007 register the
|
|
12
|
+
* commands and add them to buildProgram() in cli-runner.ts.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { readFileSync } from "fs";
|
|
16
|
+
import { dirname, join } from "path";
|
|
17
|
+
import { fileURLToPath } from "url";
|
|
18
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
19
|
+
import { GetObjectCommand, ListObjectsV2Command } from "@aws-sdk/client-s3";
|
|
20
|
+
import { mockS3WithEntries } from "../helpers/s3-list-mock.js";
|
|
21
|
+
import { mockVaultService } from "../helpers/vault-service-mock.js";
|
|
22
|
+
import { runCli } from "../helpers/cli-runner.js";
|
|
23
|
+
|
|
24
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
|
|
26
|
+
const FIXTURES = join(__dirname, "../fixtures");
|
|
27
|
+
const SOURCE_PATH = join(FIXTURES, "sources/meetings/sample.md");
|
|
28
|
+
const SIGNAL_ACTION_PATH = join(FIXTURES, "signals/action_item/sample.md");
|
|
29
|
+
const SIGNAL_SUMMARY_PATH = join(FIXTURES, "signals/summary/sample.md");
|
|
30
|
+
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// Fixture shape tests
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
describe("fixtures — file shape", () => {
|
|
36
|
+
it("source fixture has expected frontmatter fields", () => {
|
|
37
|
+
const content = readFileSync(SOURCE_PATH, "utf-8");
|
|
38
|
+
expect(content).toContain("source_id:");
|
|
39
|
+
expect(content).toContain("channel: meeting");
|
|
40
|
+
expect(content).toContain("participants:");
|
|
41
|
+
expect(content).toContain("created_at:");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("action_item signal fixture has required signal fields", () => {
|
|
45
|
+
const content = readFileSync(SIGNAL_ACTION_PATH, "utf-8");
|
|
46
|
+
expect(content).toContain("signal_id:");
|
|
47
|
+
expect(content).toContain("signal_type: action_item");
|
|
48
|
+
expect(content).toContain("source_ref:");
|
|
49
|
+
expect(content).toContain("citations:");
|
|
50
|
+
expect(content).toContain("entity_refs:");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("summary signal fixture has required signal fields", () => {
|
|
54
|
+
const content = readFileSync(SIGNAL_SUMMARY_PATH, "utf-8");
|
|
55
|
+
expect(content).toContain("signal_type: summary");
|
|
56
|
+
expect(content).toContain("source_ref:");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// S3 mock round-trip tests
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
describe("mockS3WithEntries — listing", () => {
|
|
65
|
+
it("lists all entries when no prefix filter is applied", async () => {
|
|
66
|
+
const sourceContent = readFileSync(SOURCE_PATH, "utf-8");
|
|
67
|
+
const signalContent = readFileSync(SIGNAL_ACTION_PATH, "utf-8");
|
|
68
|
+
|
|
69
|
+
const client = mockS3WithEntries({
|
|
70
|
+
entries: [
|
|
71
|
+
{ key: "sources/meetings/abc.md", content: sourceContent },
|
|
72
|
+
{ key: "signals/action_item/xyz.md", content: signalContent },
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const result = await client.send(
|
|
77
|
+
new ListObjectsV2Command({ Bucket: "mock-bucket" }),
|
|
78
|
+
) as { Contents: Array<{ Key: string; Size: number }> };
|
|
79
|
+
|
|
80
|
+
expect(result.Contents).toHaveLength(2);
|
|
81
|
+
const keys = result.Contents.map((c) => c.Key);
|
|
82
|
+
expect(keys).toContain("sources/meetings/abc.md");
|
|
83
|
+
expect(keys).toContain("signals/action_item/xyz.md");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("filters by prefix — returns only matching entries", async () => {
|
|
87
|
+
const sourceContent = readFileSync(SOURCE_PATH, "utf-8");
|
|
88
|
+
const signalContent = readFileSync(SIGNAL_ACTION_PATH, "utf-8");
|
|
89
|
+
|
|
90
|
+
const client = mockS3WithEntries({
|
|
91
|
+
entries: [
|
|
92
|
+
{ key: "sources/meetings/abc.md", content: sourceContent },
|
|
93
|
+
{ key: "signals/action_item/xyz.md", content: signalContent },
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const sourceList = await client.send(
|
|
98
|
+
new ListObjectsV2Command({ Bucket: "mock-bucket", Prefix: "sources/meetings/" }),
|
|
99
|
+
) as { Contents: Array<{ Key: string }> };
|
|
100
|
+
|
|
101
|
+
expect(sourceList.Contents).toHaveLength(1);
|
|
102
|
+
expect(sourceList.Contents[0].Key).toBe("sources/meetings/abc.md");
|
|
103
|
+
|
|
104
|
+
const signalList = await client.send(
|
|
105
|
+
new ListObjectsV2Command({ Bucket: "mock-bucket", Prefix: "signals/action_item/" }),
|
|
106
|
+
) as { Contents: Array<{ Key: string }> };
|
|
107
|
+
|
|
108
|
+
expect(signalList.Contents).toHaveLength(1);
|
|
109
|
+
expect(signalList.Contents[0].Key).toBe("signals/action_item/xyz.md");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("mockS3WithEntries — get round-trip", () => {
|
|
114
|
+
it("retrieves source content and preserves exact bytes", async () => {
|
|
115
|
+
const sourceContent = readFileSync(SOURCE_PATH, "utf-8");
|
|
116
|
+
|
|
117
|
+
const client = mockS3WithEntries({
|
|
118
|
+
entries: [{ key: "sources/meetings/abc.md", content: sourceContent }],
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const result = await client.send(
|
|
122
|
+
new GetObjectCommand({ Bucket: "mock-bucket", Key: "sources/meetings/abc.md" }),
|
|
123
|
+
) as { Body: AsyncIterable<Uint8Array> };
|
|
124
|
+
|
|
125
|
+
const chunks: Buffer[] = [];
|
|
126
|
+
for await (const chunk of result.Body) {
|
|
127
|
+
chunks.push(Buffer.from(chunk));
|
|
128
|
+
}
|
|
129
|
+
const retrieved = Buffer.concat(chunks).toString("utf-8");
|
|
130
|
+
|
|
131
|
+
expect(retrieved).toBe(sourceContent);
|
|
132
|
+
// Spot-check frontmatter field survives round-trip
|
|
133
|
+
expect(retrieved).toContain("source_id: abc-meeting-001");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("retrieves signal content and preserves exact bytes", async () => {
|
|
137
|
+
const signalContent = readFileSync(SIGNAL_ACTION_PATH, "utf-8");
|
|
138
|
+
|
|
139
|
+
const client = mockS3WithEntries({
|
|
140
|
+
entries: [{ key: "signals/action_item/xyz.md", content: signalContent }],
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const result = await client.send(
|
|
144
|
+
new GetObjectCommand({ Bucket: "mock-bucket", Key: "signals/action_item/xyz.md" }),
|
|
145
|
+
) as { Body: AsyncIterable<Uint8Array> };
|
|
146
|
+
|
|
147
|
+
const chunks: Buffer[] = [];
|
|
148
|
+
for await (const chunk of result.Body) {
|
|
149
|
+
chunks.push(Buffer.from(chunk));
|
|
150
|
+
}
|
|
151
|
+
const retrieved = Buffer.concat(chunks).toString("utf-8");
|
|
152
|
+
|
|
153
|
+
expect(retrieved).toBe(signalContent);
|
|
154
|
+
expect(retrieved).toContain("signal_type: action_item");
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("throws NoSuchKey for missing entry", async () => {
|
|
158
|
+
const client = mockS3WithEntries({ entries: [] });
|
|
159
|
+
|
|
160
|
+
await expect(
|
|
161
|
+
client.send(new GetObjectCommand({ Bucket: "mock-bucket", Key: "does/not/exist.md" })),
|
|
162
|
+
).rejects.toMatchObject({ name: "NoSuchKey" });
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
// Vault-service mock tests
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
|
|
170
|
+
describe("mockVaultService — membership endpoint", () => {
|
|
171
|
+
let restore: (() => void) | undefined;
|
|
172
|
+
|
|
173
|
+
afterEach(() => {
|
|
174
|
+
restore?.();
|
|
175
|
+
restore = undefined;
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("GET /membership/me returns memberships for all configured entities", async () => {
|
|
179
|
+
restore = mockVaultService({
|
|
180
|
+
entities: [
|
|
181
|
+
{ uid: "cmp_indigo_001", slug: "indigo", bucketName: "hq-indigo-bucket" },
|
|
182
|
+
{ uid: "prs_personal_001", slug: "personal", bucketName: "hq-personal-bucket" },
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const res = await fetch("https://vault-api.example.com/membership/me");
|
|
187
|
+
const body = (await res.json()) as { memberships: Array<{ companyUid: string }> };
|
|
188
|
+
|
|
189
|
+
expect(res.status).toBe(200);
|
|
190
|
+
expect(body.memberships).toHaveLength(2);
|
|
191
|
+
const uids = body.memberships.map((m) => m.companyUid);
|
|
192
|
+
expect(uids).toContain("cmp_indigo_001");
|
|
193
|
+
expect(uids).toContain("prs_personal_001");
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("POST /entities/{uid}/sts returns credentials", async () => {
|
|
197
|
+
restore = mockVaultService({
|
|
198
|
+
entities: [{ uid: "cmp_indigo_001", slug: "indigo", bucketName: "hq-indigo-bucket" }],
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const res = await fetch("https://vault-api.example.com/entities/cmp_indigo_001/sts", {
|
|
202
|
+
method: "POST",
|
|
203
|
+
});
|
|
204
|
+
const body = (await res.json()) as {
|
|
205
|
+
credentials: { accessKeyId: string };
|
|
206
|
+
bucketName: string;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
expect(res.status).toBe(200);
|
|
210
|
+
expect(body.credentials.accessKeyId).toBe("ASIAMOCK000000000001");
|
|
211
|
+
expect(body.bucketName).toBe("hq-indigo-bucket");
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
// CLI runner
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
|
|
219
|
+
describe("runCli — basic wiring", () => {
|
|
220
|
+
it("runCli(['hq', '--help']) exits 0 and emits non-empty stdout", async () => {
|
|
221
|
+
const result = await runCli(["hq", "--help"]);
|
|
222
|
+
expect(result.exitCode).toBe(0);
|
|
223
|
+
expect(result.stdout.length).toBeGreaterThan(0);
|
|
224
|
+
expect(result.stdout).toContain("hq");
|
|
225
|
+
});
|
|
226
|
+
});
|