Repository navigation
test(templates): prove a landed input asset becomes visible to availability #1679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // @vitest-environment node | ||
| // The unit tests inject `access`, so they prove the branch but not that the | ||
| // component placing a file and the one looking for it pick the same path. Here | ||
| // the real writer chooses the destination and the real reader is asked about | ||
| // it; only the network boundary is replaced. | ||
| import fs from 'fs' | ||
| import os from 'os' | ||
| import path from 'path' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import type { InstallationRecord } from '../../installations' | ||
|
|
||
| vi.mock('electron', () => ({ | ||
| app: { | ||
| isPackaged: false, | ||
| getPath: () => os.tmpdir(), | ||
| getVersion: () => '0.0.0-test', | ||
| getLocale: () => 'en' | ||
| } | ||
| })) | ||
|
|
||
| /** Writes to whatever destination the writer chose, as a transfer would. */ | ||
| const download = vi.fn(async (_url: string, destPath: string) => { | ||
| await fs.promises.mkdir(path.dirname(destPath), { recursive: true }) | ||
| await fs.promises.writeFile(destPath, 'bytes') | ||
| }) | ||
|
|
||
| vi.mock('../../lib/download', () => ({ | ||
| download: (...args: unknown[]) => download(...(args as [string, string])) | ||
| })) | ||
|
|
||
| const { downloadTemplateInputAssets, resolveTemplateInputAssetAvailability } = | ||
| await import('./templateInputAssets') | ||
|
|
||
| const ASSET = 'subject.png' | ||
| const workflow = { nodes: [{ type: 'LoadImage', widgets_values: [ASSET] }] } | ||
|
|
||
| let installPath: string | ||
| const log = () => {} | ||
|
|
||
| function installation(): InstallationRecord { | ||
| // Without `useSharedInput: false` the lookup escapes to the user's own | ||
| // configured input directory. | ||
| return { id: 'inst-test', installPath, useSharedInput: false } as InstallationRecord | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ Nit — The suite performs real filesystem writes and relies on |
||
| } | ||
|
|
||
| function availability(name: string) { | ||
| return resolveTemplateInputAssetAvailability(installation(), [name]).then(([entry]) => entry) | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| download.mockClear() | ||
| installPath = fs.mkdtempSync(path.join(os.tmpdir(), 'comfy-input-contract-')) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(installPath, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| describe('a downloaded template input asset', () => { | ||
| it('lands where the availability reader looks for it', async () => { | ||
| expect(await availability(ASSET)).toEqual({ | ||
| filename: ASSET, | ||
| status: 'missing' | ||
| }) | ||
|
|
||
| const placed = await downloadTemplateInputAssets( | ||
| installation(), | ||
| 'template-a', | ||
| log, | ||
| undefined, | ||
| workflow | ||
| ) | ||
|
|
||
| expect(placed).toEqual([{ filename: ASSET, downloaded: true }]) | ||
| expect(await availability(ASSET)).toEqual({ | ||
| filename: ASSET, | ||
| status: 'present' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Low — This test shows the writer and reader agree on the path, but |
||
| }) | ||
| }) | ||
|
|
||
| it('is not fetched again when it is already there', async () => { | ||
| await downloadTemplateInputAssets(installation(), 'template-a', log, undefined, workflow) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Low — The idempotency guarantee asserted here only holds for sequential calls: the |
||
| download.mockClear() | ||
|
|
||
| const placed = await downloadTemplateInputAssets( | ||
| installation(), | ||
| 'template-a', | ||
| log, | ||
| undefined, | ||
| workflow | ||
| ) | ||
|
|
||
| expect(placed).toEqual([{ filename: ASSET, downloaded: false }]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium — The stub |
||
| expect(download).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('answers nothing for a name that escapes the input directory', async () => { | ||
| await expect( | ||
| resolveTemplateInputAssetAvailability(installation(), [ | ||
| '../escaped.png', | ||
| 'nested/subject.png' | ||
| ]) | ||
| ).resolves.toEqual([]) | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low — The
downloadmock is typed and cast as a two-argument function, so thesignalthat production passes (download(url, destPath, null, { signal })) is dropped, and every call site here passesundefinedfor the abort signal. Widening the mock signature and adding a cancellation case would exercise the abort path the install task always supplies. Raised by 1 of 8 reviewers (claude-opus-5-thinking-max adversarial).