Skip to content

Commit 291f044

Browse files
committed
test(plugin-audit): the stand-in's answer lives in one helper, so the find double is judged by the limit gate (ADR-0139 E7)
Claude-Session: https://claude.ai/code/session_01NX4Woa8XhvMs6xpqQpx8kK Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8ac4edd commit 291f044

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

‎packages/plugins/plugin-audit/src/comment-thread-leaf.test.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ const silentLogger = () => ({ info: vi.fn(), warn: vi.fn(), debug: vi.fn() });
2222

2323
const PAIR_FIELDS = { thread_id: {}, body: {}, object_name: {}, record_id: {} };
2424

25+
/**
26+
* What the stand-in answers: the comments with no stamped pair (the only rows
27+
* this gate pre-scans), or the requested parent ids the caller may read.
28+
*/
29+
function standInRows(
30+
opts: { comments?: Array<Record<string, unknown>>; readable?: Record<string, string[]> },
31+
object: string,
32+
requested: unknown,
33+
): Array<Record<string, unknown>> {
34+
if (object === 'sys_comment') return (opts.comments ?? []).filter((r) => r.object_name == null);
35+
const ids = Array.isArray(requested) ? requested.map(String) : [];
36+
return ids.filter((id) => (opts.readable?.[object] ?? []).includes(id)).map((id) => ({ id }));
37+
}
38+
2539
type Mw = (ctx: CommentReadMiddlewareCtx, next: () => Promise<void>) => Promise<void>;
2640

2741
/** A stand-in engine: one registry, the D5 questions answered by name, every find recorded. */
@@ -50,13 +64,7 @@ function standIn(opts: {
5064
: undefined,
5165
find: async (object: string, options: any) => {
5266
finds.push({ object, options });
53-
const rows =
54-
object === 'sys_comment'
55-
? (opts.comments ?? []).filter((r) => r.object_name == null)
56-
: ((options?.where?.id?.$in ?? []) as unknown[])
57-
.map(String)
58-
.filter((id) => (opts.readable?.[object] ?? []).includes(id))
59-
.map((id) => ({ id }));
67+
const rows = standInRows(opts, object, options?.where?.id?.$in);
6068
return typeof options?.limit === 'number' ? rows.slice(0, options.limit) : rows;
6169
},
6270
};

0 commit comments

Comments
 (0)