Skip to content

Commit c075544

Browse files
committed
test(dogfood): the field-zoo round-trip writes real files into its media fields
The matrix wrote ids that name no file, relying on the write keeping them as written. Such a write is now refused at the field, so the HTTP suite uploads one real file per media field and asserts the read form carries its id. The matrix keeps its stored-shape stand-ins for the value-shape test. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EGkwyoUjm7LjHY7uBXFSgv
1 parent 66398e7 commit c075544

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

‎packages/qa/dogfood/test/field-zoo-roundtrip.dogfood.test.ts‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
2020
import { SECRET_MASK } from '@objectstack/objectql';
21+
import { FILE_REFERENCE_TYPES } from '@objectstack/spec/data';
2122
import { type VerifyStack } from '@objectstack/verify';
2223
import { bootShowcase } from './showcase-boot.js';
2324

@@ -27,6 +28,8 @@ describe('dogfood: field-type capability matrix round-trips over HTTP (#2004)',
2728
let record: Record<string, unknown>;
2829
/** Resolved reference ids, keyed by field — the assertions compare to these. */
2930
const referenceIds: Record<string, string> = {};
31+
/** Uploaded `sys_file` ids, keyed by media field — the assertions compare to these. */
32+
const fileIds: Record<string, string> = {};
3033

3134
beforeAll(async () => {
3235
stack = await bootShowcase();
@@ -54,13 +57,38 @@ describe('dogfood: field-type capability matrix round-trips over HTTP (#2004)',
5457
referenceIds[target.field] = id as string;
5558
}
5659

60+
// [#26043] Upload a REAL file for each media field. A write naming an id
61+
// that is no file of the organization is now refused at the field, as one
62+
// naming a file the writer may not read is, so the matrix's stand-in ids
63+
// would be refused. What this file proves for the media family is
64+
// unchanged: the stored id round-trips as the same file.
65+
for (const c of MATRIX) {
66+
if (!FILE_REFERENCE_TYPES.has(c.type) || !('write' in c.check) || c.check.write === undefined) continue;
67+
const bytes = `zoo ${c.field}`;
68+
const presign = await stack.apiAs(token, 'POST', '/storage/upload/presigned', {
69+
filename: `${c.field}.txt`, mimeType: 'text/plain', size: bytes.length,
70+
});
71+
expect(presign.status, `presign for ${c.field}`).toBe(200);
72+
const { data } = (await presign.json()) as { data: { uploadUrl: string; fileId: string; headers?: Record<string, string> } };
73+
const put = await stack.raw(String(data.uploadUrl).replace(/^https?:\/\/[^/]+/, ''), {
74+
method: 'PUT', headers: data.headers ?? { 'content-type': 'text/plain' }, body: bytes,
75+
});
76+
expect(put.status, `upload for ${c.field}`).toBeLessThan(300);
77+
const complete = await stack.apiAs(token, 'POST', '/storage/upload/complete', { fileId: data.fileId });
78+
expect(complete.status, `complete for ${c.field}`).toBe(200);
79+
fileIds[c.field] = String(data.fileId);
80+
}
81+
5782
// Build the create body from every entry that carries a `write` value
5883
// (+ required name). `present`/`computed` server-owned fields are skipped.
59-
// A reference placeholder resolves to the id seeded above.
84+
// A reference placeholder resolves to the id seeded above, and a media
85+
// field to the file uploaded above.
6086
const body: Record<string, unknown> = { name: 'zoo-roundtrip' };
6187
for (const c of MATRIX) {
6288
if (!('write' in c.check) || c.check.write === undefined) continue;
63-
body[c.field] = c.field in referenceIds ? referenceIds[c.field] : c.check.write;
89+
body[c.field] = c.field in referenceIds
90+
? referenceIds[c.field]
91+
: c.field in fileIds ? fileIds[c.field] : c.check.write;
6492
}
6593

6694
const created = await stack.apiAs(token, 'POST', '/data/showcase_field_zoo', body);
@@ -88,6 +116,13 @@ describe('dogfood: field-type capability matrix round-trips over HTTP (#2004)',
88116
const actual = record[c.field];
89117
switch (c.check.kind) {
90118
case 'equal':
119+
// A media field reads back in its expanded form, the file object
120+
// the stored id resolves to (ADR-0104 D3 wave 2), so its `id` is
121+
// the stored id.
122+
if (c.field in fileIds) {
123+
expect(actual).toMatchObject({ id: fileIds[c.field] });
124+
break;
125+
}
91126
expect(actual).toEqual(
92127
c.field in referenceIds ? referenceIds[c.field] : c.check.write,
93128
);

‎packages/qa/dogfood/test/field-zoo.matrix.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ export const MATRIX: FieldCase[] = [
138138
{ field: 'f_record', type: 'record', check: { kind: 'equal', write: { home: '+1', work: '+2' } } },
139139
// media — the STORED form is an opaque sys_file id (ADR-0104 D3 wave 2); the
140140
// inline `{url, …}` blob is the expanded READ form, derived by the resolver
141-
// rather than written. These ids match no sys_file row here, which is the
142-
// point: the round-trip must return the stored id verbatim when there is
143-
// nothing to expand it into.
141+
// rather than written. The `write` values are stand-ins in the stored shape
142+
// (the value-shape test parses them): [#26043] a write naming an id that is
143+
// no file of the organization is refused, so the HTTP suite uploads a real
144+
// file for each and asserts the read form carries its id.
144145
{ field: 'f_video', type: 'video', check: { kind: 'equal', write: 'file_zoo_video' } },
145146
{ field: 'f_audio', type: 'audio', check: { kind: 'equal', write: 'file_zoo_audio' } },
146147
{ field: 'f_composite', type: 'composite', check: { kind: 'equal', write: { label: 'x', n: 1 } } },

0 commit comments

Comments
 (0)