Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/lib/helpers/files.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest';
import {
DEPLOYMENT_ARCHIVE_EXTENSIONS,
getInvalidDeploymentArchiveReason
} from './files';

describe('deployment archive extensions', () => {
it('should include the compound tar.gz extension for the file picker accept attribute', () => {
// On macOS a bare '.gz' accept token does not match 'code.tar.gz' files
// (compound tar+gzip UTI), greying them out in the picker.
expect(DEPLOYMENT_ARCHIVE_EXTENSIONS).toContain('tar.gz');
expect(DEPLOYMENT_ARCHIVE_EXTENSIONS).toContain('gz');
});
Comment on lines +12 to +13

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test Mirrors Implementation

These assertions repeat the exact entries stored in DEPLOYMENT_ARCHIVE_EXTENSIONS. They can pass without proving that the rendered file picker produces a usable .gz,.tar.gz accept value, and they will fail after harmless changes to the configuration's representation. This violates the repository directive to test observable behavior rather than mirror source configuration. Replace this with a test that renders the dropzone or input and checks the resulting picker behavior before merging.

Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/helpers/files.test.ts
Line: 12-13

Comment:
**Test Mirrors Implementation**

These assertions repeat the exact entries stored in `DEPLOYMENT_ARCHIVE_EXTENSIONS`. They can pass without proving that the rendered file picker produces a usable `.gz,.tar.gz` accept value, and they will fail after harmless changes to the configuration's representation. This violates the repository directive to test observable behavior rather than mirror source configuration. Replace this with a test that renders the dropzone or input and checks the resulting picker behavior before merging.

**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex


it('should accept .tar.gz archives and reject other files', () => {
const ok = [new File(['x'], 'code.tar.gz')];
expect(getInvalidDeploymentArchiveReason(ok)).toBeNull();

const upper = [new File(['x'], 'CODE.TAR.GZ')];
expect(getInvalidDeploymentArchiveReason(upper)).toBeNull();

const zip = [new File(['x'], 'code.zip')];
expect(getInvalidDeploymentArchiveReason(zip)).toBe('invalid_extension');
});
});
10 changes: 10 additions & 0 deletions src/lib/helpers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ export async function gzipUpload(files: FileList) {
return uploadFile;
}

/**
* Extensions accepted for manual deployment archives.
*
* 'tar.gz' must be listed alongside 'gz': the file picker `accept` attribute is
* built from these extensions, and on macOS a bare '.gz' token does not match
* 'code.tar.gz' files (their UTI is the compound tar+gzip type), so the picker
* greys them out.
*/
export const DEPLOYMENT_ARCHIVE_EXTENSIONS = ['gz', 'tar.gz'];

export function getInvalidDeploymentArchiveReason(
files: FileList | File[] | null | undefined,
maxSize?: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import {
getInvalidDeploymentArchiveReason,
InvalidFileType,
removeFile
removeFile,
DEPLOYMENT_ARCHIVE_EXTENSIONS
} from '$lib/helpers/files';
import { isCloud } from '$lib/system';
import { humanFileSize } from '$lib/helpers/sizeConvertion';
Expand Down Expand Up @@ -224,7 +225,7 @@
<Upload.Dropzone
bind:files
title="Upload function"
extensions={['gz']}
extensions={DEPLOYMENT_ARCHIVE_EXTENSIONS}
{maxSize}
required
on:invalid={handleInvalid}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import {
getInvalidDeploymentArchiveReason,
InvalidFileType,
removeFile
removeFile,
DEPLOYMENT_ARCHIVE_EXTENSIONS
} from '$lib/helpers/files';
import { addNotification } from '$lib/stores/notifications';
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
Expand Down Expand Up @@ -93,7 +94,7 @@
Upload a tar.gz file containing your function source code
</Typography.Text>
<Upload.Dropzone
extensions={['gz']}
extensions={DEPLOYMENT_ARCHIVE_EXTENSIONS}
bind:files
{maxSize}
required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import {
getInvalidDeploymentArchiveReason,
InvalidFileType,
removeFile
removeFile,
DEPLOYMENT_ARCHIVE_EXTENSIONS
} from '$lib/helpers/files';
import { humanFileSize } from '$lib/helpers/sizeConvertion';
import { isCloud } from '$lib/system';
Expand Down Expand Up @@ -219,7 +220,7 @@
Upload a tar.gz containing your site source code
</Typography.Text>
<Upload.Dropzone
extensions={['gz']}
extensions={DEPLOYMENT_ARCHIVE_EXTENSIONS}
bind:files
{maxSize}
required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import {
getInvalidDeploymentArchiveReason,
InvalidFileType,
removeFile
removeFile,
DEPLOYMENT_ARCHIVE_EXTENSIONS
} from '$lib/helpers/files';
import { addNotification } from '$lib/stores/notifications';
import { uploader } from '$lib/stores/uploader';
Expand Down Expand Up @@ -93,7 +94,7 @@
Upload a tar.gz file containing your site source code
</Typography.Text>
<Upload.Dropzone
extensions={['gz']}
extensions={DEPLOYMENT_ARCHIVE_EXTENSIONS}
bind:files
{maxSize}
required
Expand Down