Skip to content

Commit 2e53abd

Browse files
committed
test(plugin-audit): count the audit summary's reads, not the write's reference check
The write's reference check reads each lookup or user value it names through the caller's read door, projected to id alone. The read-count pins measure what the audit summary reads, so that read is left out of their counters. The log line for a failed caller read names a referenced record rather than a master-detail header, as the read now serves lookup and user values too. Claude-Session: https://claude.ai/code/session_01Utp6CYQjMkN514R78sCrTT Co-authored-by: Claude <noreply@anthropic.com>
1 parent eda7ee2 commit 2e53abd

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎packages/objectql/src/engine-referential-integrity.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ export async function masterDetailHeadersCallerReads(
384384
}
385385
return served;
386386
} catch (err) {
387-
this.logger?.warn?.('the caller\'s read of the master-detail header failed — the header binds as a missing header', {
387+
this.logger?.warn?.('the caller\'s read of the referenced record failed — it answers as a record that does not exist', {
388388
object: master, error: err,
389389
});
390390
return new Set();

‎packages/plugins/plugin-audit/src/audit-lookup-summary.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ function makeCountingDriver() {
174174
async connect() {}, async disconnect() {}, async checkHealth() { return true; },
175175
async execute() { return null; },
176176
async find(object: string, ast: any) {
177-
reads.findOn[object] = (reads.findOn[object] ?? 0) + 1;
177+
// [#29029] The write's own reference check reads each lookup / user
178+
// value it names through the caller's read door, projected to `id`
179+
// alone: that read is the write's, not this plugin's, so it is not
180+
// counted here.
181+
const referenceCheckRead = Array.isArray(ast?.fields) && ast.fields.length === 1 && ast.fields[0] === 'id';
182+
if (!referenceCheckRead) reads.findOn[object] = (reads.findOn[object] ?? 0) + 1;
178183
return Array.from(storeFor(object).values()).filter((r) => matches(r, ast?.where)).map(copy);
179184
},
180185
async findOne(object: string, ast: any) {

‎packages/plugins/plugin-audit/src/audit-milestone-summary.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,12 @@ function makeCountingDriver() {
223223
async connect() {}, async disconnect() {}, async checkHealth() { return true; },
224224
async execute() { return null; },
225225
async find(object: string, ast: any) {
226-
reads.findOn[object] = (reads.findOn[object] ?? 0) + 1;
226+
// [#29029] The write's own reference check reads each lookup / user
227+
// value it names through the caller's read door, projected to `id`
228+
// alone: that read is the write's, not this plugin's, so it is not
229+
// counted here.
230+
const referenceCheckRead = Array.isArray(ast?.fields) && ast.fields.length === 1 && ast.fields[0] === 'id';
231+
if (!referenceCheckRead) reads.findOn[object] = (reads.findOn[object] ?? 0) + 1;
227232
return Array.from(storeFor(object).values()).filter((r) => matches(r, ast?.where)).map(copy);
228233
},
229234
async findOne(object: string, ast: any) {

‎packages/plugins/plugin-audit/src/audit-option-label-summary.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,12 @@ function makeCountingDriver() {
247247
async connect() {}, async disconnect() {}, async checkHealth() { return true; },
248248
async execute() { return null; },
249249
async find(object: string, ast: any) {
250-
reads.findOn[object] = (reads.findOn[object] ?? 0) + 1;
250+
// [#29029] The write's own reference check reads each lookup / user
251+
// value it names through the caller's read door, projected to `id`
252+
// alone: that read is the write's, not this plugin's, so it is not
253+
// counted here.
254+
const referenceCheckRead = Array.isArray(ast?.fields) && ast.fields.length === 1 && ast.fields[0] === 'id';
255+
if (!referenceCheckRead) reads.findOn[object] = (reads.findOn[object] ?? 0) + 1;
251256
return Array.from(storeFor(object).values()).filter((r) => matches(r, ast?.where)).map(copy);
252257
},
253258
async findOne(object: string, ast: any) {

‎packages/plugins/plugin-audit/src/implicit-reference-target-summary.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,13 @@ function makeCountingDriver() {
194194
// non-function declaration it cannot supply — `reads` among them — and
195195
// arithmetic on that stub throws before the body can be judged at all,
196196
// which files the double as UNJUDGED rather than as conforming.
197+
// [#29029] The write's own reference check reads each lookup / user
198+
// value it names through the caller's read door, projected to `id`
199+
// alone: that read is the write's, not this plugin's, so it is not
200+
// counted here.
201+
const referenceCheckRead = Array.isArray(ast?.fields) && ast.fields.length === 1 && ast.fields[0] === 'id';
197202
const prior = reads.findOn[object];
198-
reads.findOn[object] = (typeof prior === 'number' ? prior : 0) + 1;
203+
if (!referenceCheckRead) reads.findOn[object] = (typeof prior === 'number' ? prior : 0) + 1;
199204
const matched = Array.from(storeFor(object).values())
200205
.filter((r) => matches(r, ast?.where));
201206
// The caller's bound: applied by PRESENCE (so `limit: 0` returns nothing),

0 commit comments

Comments
 (0)