diff --git a/server/scripts/pg-probe/arg-samples.ts b/server/scripts/pg-probe/arg-samples.ts index 1e3848005..37ef2f02f 100644 --- a/server/scripts/pg-probe/arg-samples.ts +++ b/server/scripts/pg-probe/arg-samples.ts @@ -28,9 +28,10 @@ const MAX_DEPTH = 4; /** * The label of the flag in the repositories' `[present: boolean, value]` * pairs (`presenceSet`): a patch whose pairs are all absent sends no SQL, so - * this one boolean is sampled true. Every other boolean stays false. + * this one boolean is sampled true. Every other boolean stays false. The + * label is spelled in `presenceSet`'s signature, which a test pins. */ -const PRESENCE_LABEL = 'present'; +export const PRESENCE_LABEL = 'present'; const SAMPLE_DATE = '2026-01-01'; const SAMPLE_TIMESTAMP = '2026-01-01 00:00:00'; @@ -98,7 +99,12 @@ function sampleObjectType(checker: ts.TypeChecker, type: ts.ObjectType, name: st const labels = ((type as ts.TypeReference).target as ts.TupleType).labeledElementDeclarations; for (const [i, element] of checker.getTypeArguments(type as ts.TypeReference).entries()) { const label = labels?.[i]?.name; - const sample = sampleFor(checker, element, label && ts.isIdentifier(label) ? label.text : `${name}[${i}]`, depth + 1); + const sample = sampleFor( + checker, + element, + label && ts.isIdentifier(label) ? label.text : `${name}[${i}]`, + depth + 1, + ); if (!sample.ok) return sample; values.push(sample.value); } diff --git a/server/tests/unit/scripts/pg-probe/arg-samples.test.ts b/server/tests/unit/scripts/pg-probe/arg-samples.test.ts index dfcecab5e..2f4ff9b48 100644 --- a/server/tests/unit/scripts/pg-probe/arg-samples.test.ts +++ b/server/tests/unit/scripts/pg-probe/arg-samples.test.ts @@ -7,13 +7,14 @@ * sample (or a pinned reason it has none). */ import { + PRESENCE_LABEL, planRepositories, readCompilerOptions, sampleString, type MethodPlan, } from '../../../../scripts/pg-probe/arg-samples'; -import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import path from 'node:path'; import ts from 'typescript'; @@ -154,6 +155,21 @@ describe('pg-probe argument samples', () => { expect(argsOf('presence')).toEqual([{ name: [true, 'probe'], flag: [false, 1] }]); }); + it('PGPROBE-038: the presence label the sampler reads is the one presenceSet declares', () => { + // The sampler matches the tuple label by name; a rename in the repository + // helper would stop the flag being sampled true, silently unmeasuring every + // partial update. Read the real signature, not a copy of it. + const file = path.join(__dirname, '../../../../src/db/repositories/_shared/presence-set.ts'); + const source = ts.createSourceFile(file, readFileSync(file, 'utf8'), ts.ScriptTarget.Latest, true); + const labels: string[] = []; + const visit = (node: ts.Node): void => { + if (ts.isNamedTupleMember(node)) labels.push(node.name.text); + ts.forEachChild(node, visit); + }; + visit(source); + expect(labels).toContain(PRESENCE_LABEL); + }); + it('PGPROBE-035: a required callback makes the method unprobeable, an optional one is left off', () => { expect(planOf('withCallback')).toMatchObject({ unprobeable: 'fn: a function parameter' }); expect(argsOf('optionalCallback')).toEqual([1]);