Skip to content

Commit 8993840

Browse files
committed
test(objectql): pin the refusal of a projection whose every column is unknown
Claude-Session: https://claude.ai/code/session_01L6bhgXcN9HaZYSEUdJWEjw Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7e200b4 commit 8993840

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

‎packages/objectql/src/engine-empty-projection-refusal.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,48 @@ describe('[#27008] the in-process engine refuses an empty projection', () => {
216216
expect(row).toEqual({ title: 'Ship', project_id: { name: 'Apollo' } });
217217
});
218218
});
219+
220+
/**
221+
* [#27165] A projection that is empty AFTER the unknown-plain-column tolerance
222+
* dropped every entry is an empty projection, and is refused with the same
223+
* refusal. Before, `find(obj, { fields: ['nope'] })` dropped `nope` (the #7589
224+
* tolerance) and then fell back to every column: a narrower request answered
225+
* wider. The tolerance itself stays for a mix of known and unknown columns.
226+
*/
227+
describe('[#27165] a projection whose every column is unknown is an empty projection', () => {
228+
let engine: ObjectQL;
229+
let reads: Array<{ object: string; fields: unknown }>;
230+
231+
beforeEach(async () => {
232+
engine = new ObjectQL();
233+
const made = makeDriver();
234+
reads = made.reads;
235+
engine.registerDriver(made.driver, true);
236+
await engine.init();
237+
engine.registry.registerObject(projectObject, 'test-package');
238+
engine.registry.registerObject(taskObject, 'test-package');
239+
});
240+
241+
it('find with only unknown columns is refused 400 VALIDATION_ERROR, naming them, before any driver read', async () => {
242+
const answer = await wireAnswer(engine.find('task_27008', { fields: ['nope', 'nada'] }));
243+
expect(answer).toMatchObject({ status: 400, code: 'VALIDATION_ERROR' });
244+
expect(answer.message).toContain(declaredRefusal());
245+
expect(answer.message).toMatch(/^ObjectQL\.find\('task_27008'\) names no field in 'fields': got \["nope","nada"\]/);
246+
expect(reads).toEqual([]);
247+
});
248+
249+
it('findOne with only unknown columns is refused the same way, before any driver read', async () => {
250+
const answer = await wireAnswer(engine.findOne('task_27008', { where: { id: 't1' }, fields: ['nope'] }));
251+
expect(answer).toMatchObject({ status: 400, code: 'VALIDATION_ERROR' });
252+
expect(answer.message).toContain(declaredRefusal());
253+
expect(answer.message).toMatch(/^ObjectQL\.findOne\('task_27008'\) names no field in 'fields': got \["nope"\]/);
254+
expect(reads).toEqual([]);
255+
});
256+
257+
it('CONTROL: a mix of known and unknown columns keeps the tolerance and projects the known ones', async () => {
258+
const [row] = await engine.find('task_27008', { fields: ['nope', 'title'] });
259+
expect(row).toEqual({ title: 'Ship' });
260+
const one = await engine.findOne('task_27008', { where: { id: 't1' }, fields: ['nope', 'title'] });
261+
expect(one).toEqual({ title: 'Ship' });
262+
});
263+
});

0 commit comments

Comments
 (0)