mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-12 23:31:02 +00:00
89c33ac3f4
The chips offered to keep an attached file in Files, but nothing could do it: the assistant's upload_trip_file stays denied, and the file never reached Files. A new server write, keep_attached_file, is offered to the model where the thread holds an attachment and held as a change card naming the file and the booking, expense or place it goes with. Applied, it runs the checks of a Files upload with the user's rights (the demo block, the trip, file_upload and file_edit for a link, the instance's file types, every linked id on the same trip), copies the bytes to a trip file of their own, and writes the trip file, its expense link and the attachment's pointer to it in one transaction; the members' planners get file:created after it. A second keep of the same attachment answers the file kept the first time. FilesService gains storeBytes and discardBytes so the storage write stays out of that transaction. The receipt opens the Files tab; the card's verb, its "Attached to" row and the receipt's open label are new keys in all 27 locales. Undo is not offered: no tool takes a trip file back yet.
35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
import {
|
|
assistantAttachmentIdSchema,
|
|
assistantKeepFileArgsSchema,
|
|
assistantReadAttachedFileArgsSchema,
|
|
} from './assistant-attachments.schema';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const ID = '0b7c2f0e-6f6d-4a8e-9b1a-3d2c1e0f9a87';
|
|
|
|
describe('assistant attachments contract', () => {
|
|
it('takes an attachment only by a uuid, never a path or a number', () => {
|
|
expect(assistantAttachmentIdSchema.safeParse(ID).success).toBe(true);
|
|
for (const bad of ['../x', '42', '', 42, null]) {
|
|
expect(assistantAttachmentIdSchema.safeParse(bad).success).toBe(false);
|
|
}
|
|
});
|
|
|
|
it('reads the model arguments of read_attached_file and drops what the server sets itself', () => {
|
|
expect(assistantReadAttachedFileArgsSchema.parse({ attachmentId: ID, name: 'x.pdf' })).toEqual({
|
|
attachmentId: ID,
|
|
});
|
|
expect(assistantReadAttachedFileArgsSchema.safeParse({}).success).toBe(false);
|
|
});
|
|
|
|
it('keeps a file with plain ids of the trip, never a string or a negative id, and a short description', () => {
|
|
const kept = { attachmentId: ID, reservation_id: 5, budget_item_id: 7, place_id: 9, description: 'Airbnb' };
|
|
expect(assistantKeepFileArgsSchema.parse({ ...kept, name: 'x.pdf' })).toEqual(kept);
|
|
expect(assistantKeepFileArgsSchema.parse({ attachmentId: ID })).toEqual({ attachmentId: ID });
|
|
for (const bad of [{ reservation_id: '5' }, { budget_item_id: -1 }, { description: 'x'.repeat(1001) }]) {
|
|
expect(assistantKeepFileArgsSchema.safeParse({ attachmentId: ID, ...bad }).success).toBe(false);
|
|
}
|
|
});
|
|
});
|