Skip to content

Commit 1a1a982

Browse files
committed
feat(node): add image describe intent
1 parent d9181f0 commit 1a1a982

5 files changed

Lines changed: 590 additions & 4 deletions

File tree

packages/node/scripts/test-intents-e2e.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,35 @@ verify_file_decompress() {
9797
grep -F 'Hello from Transloadit CLI intents' "$1/input.txt" >/dev/null
9898
}
9999

100+
verify_image_describe_labels() {
101+
node --input-type=module <<'NODE' "$1"
102+
import { readFileSync } from 'node:fs'
103+
104+
const value = JSON.parse(readFileSync(process.argv[1], 'utf8'))
105+
const ok =
106+
Array.isArray(value) &&
107+
value.length > 0 &&
108+
value.every((item) => typeof item === 'string' || (item && typeof item.name === 'string'))
109+
110+
process.exit(ok ? 0 : 1)
111+
NODE
112+
}
113+
114+
verify_image_describe_wordpress() {
115+
node --input-type=module <<'NODE' "$1"
116+
import { readFileSync } from 'node:fs'
117+
118+
const value = JSON.parse(readFileSync(process.argv[1], 'utf8'))
119+
const required = ['altText', 'title', 'caption', 'description']
120+
const ok =
121+
value &&
122+
typeof value === 'object' &&
123+
required.every((key) => typeof value[key] === 'string' && value[key].trim().length > 0)
124+
125+
process.exit(ok ? 0 : 1)
126+
NODE
127+
}
128+
100129
verify_output() {
101130
local verifier="$1"
102131
local path="$2"
@@ -111,6 +140,8 @@ verify_output() {
111140
video-thumbs) verify_video_thumbs "$path" ;;
112141
video-encode-hls) verify_video_encode_hls "$path" ;;
113142
file-decompress) verify_file_decompress "$path" ;;
143+
image-describe-labels) verify_image_describe_labels "$path" ;;
144+
image-describe-wordpress) verify_image_describe_wordpress "$path" ;;
114145
*)
115146
echo "Unknown verifier: $verifier" >&2
116147
return 1
@@ -198,6 +229,31 @@ for (const smokeCase of intentSmokeCases) {
198229
smokeCase.verifier,
199230
].join('\t'))
200231
}
232+
233+
for (const smokeCase of [
234+
{
235+
name: 'image-describe-labels',
236+
paths: ['image', 'describe'],
237+
args: ['--input', '@fixture/input.jpg', '--fields', 'labels'],
238+
outputPath: 'image-describe-labels.json',
239+
verifier: 'image-describe-labels',
240+
},
241+
{
242+
name: 'image-describe-wordpress',
243+
paths: ['image', 'describe'],
244+
args: ['--input', '@fixture/input.jpg', '--for', 'wordpress'],
245+
outputPath: 'image-describe-wordpress.json',
246+
verifier: 'image-describe-wordpress',
247+
},
248+
]) {
249+
console.log([
250+
smokeCase.name,
251+
smokeCase.paths.join(' '),
252+
smokeCase.args.join('\x1f'),
253+
smokeCase.outputPath,
254+
smokeCase.verifier,
255+
].join('\t'))
256+
}
201257
NODE
202258
)
203259

packages/node/src/cli/commands/assemblies.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,12 @@ interface AssemblyDownloadTarget {
565565
targetPath: string | null
566566
}
567567

568+
const STALE_OUTPUT_GRACE_MS = 1000
569+
570+
function isMeaningfullyNewer(newer: Date, older: Date): boolean {
571+
return newer.getTime() - older.getTime() > STALE_OUTPUT_GRACE_MS
572+
}
573+
568574
async function buildDirectoryDownloadTargets({
569575
allFiles,
570576
baseDir,
@@ -719,7 +725,7 @@ async function shouldSkipStaleOutput({
719725
}
720726

721727
if (inputPaths.length === 1) {
722-
return outputStat.mtime > outputPlanMtime
728+
return isMeaningfullyNewer(outputStat.mtime, outputPlanMtime)
723729
}
724730

725731
const inputStats = await Promise.all(
@@ -737,7 +743,7 @@ async function shouldSkipStaleOutput({
737743
}
738744

739745
return inputStats.every((inputStat) => {
740-
return inputStat != null && outputStat.mtime > inputStat.mtime
746+
return inputStat != null && isMeaningfullyNewer(outputStat.mtime, inputStat.mtime)
741747
})
742748
}
743749

@@ -1397,13 +1403,14 @@ export async function create(
13971403
if (!assembly.results) throw new Error('No results in assembly')
13981404

13991405
if (
1400-
await shouldSkipStaleOutput({
1406+
!singleAssemblyMode &&
1407+
(await shouldSkipStaleOutput({
14011408
inputPaths,
14021409
outputPath: outputPlan?.path ?? null,
14031410
outputPlanMtime: outputPlan?.mtime ?? new Date(0),
14041411
outputRootIsDirectory,
14051412
reprocessStale,
1406-
})
1413+
}))
14071414
) {
14081415
outputctl.debug(`SKIPPED STALE RESULT ${inPath ?? 'null'} ${outputPlan?.path ?? 'null'}`)
14091416
return assembly

0 commit comments

Comments
 (0)