Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: read Unix LIST dates when get-uri's FTP adapter lacks MDTM and MLSD (#9462)
Adam Eivydd4b383a9c22
diff --git a/docs/DEPS.md b/docs/DEPS.mdindex 2f7ae2f081..5abd4937a0 100644--- a/docs/DEPS.md+++ b/docs/DEPS.md@@ -187,6 +187,12 @@ These exist purely to force-bump transitive deps; revisit if `npm audit` flags nPackages that legitimately need an install script are named explicitly in the allowlist in `scripts/trusted-rebuilds.js`, the single source consumed by `npm run setup`, `scripts/ensure-deps.js`, `setup.ps1`, `update.sh` / `update.ps1`, and CI. `scripts/trusted-rebuilds.test.js` fails if a workspace `.npmrc` loses the setting, or if a dependency appears with an install hook that nobody has explicitly decided about. Because CI caches `server/node_modules` between jobs, `scripts/trusted-rebuild-stamp.js` writes a mark into the tree in the same step that rebuilds it and checks that mark after a cache restore — a tree cached before the rebuild is otherwise indistinguishable from a good one, since the allowlisted packages all ship prebuilt bindings and import fine either way.+### Install-time dependency patches++`scripts/lib/getUriFtpPatch.js` carries one narrowly scoped patch for a defect upstream has not fixed (get-uri through 8.0.1): its FTP adapter reads only `entry.modifiedAt`, which basic-ftp fills from MLSD alone, so a server with neither MDTM nor MLSD made an existing file report `ENOTFOUND` (#9462). The patch falls back to the Unix `LIST` date (`rawModifiedAt`). It runs from `scripts/trusted-rebuilds.js` (`rebuildTrusted` for every workspace, and `runCli server` for the root tree that holds pm2) because `ignore-scripts=true` rules out a postinstall hook; `scripts/trusted-rebuild-stamp.js` folds the patch fingerprint into the mark so a CI-cached tree from before a patch change is rebuilt. The patch edits by exact anchor, is idempotent, and leaves an unrecognized get-uri untouched with a warning — `server/dependency-overrides.test.js` pins the lockfile to the targeted release so a bump re-verifies the anchor.++Date semantics: LIST carries no timezone, so values are read as UTC (the zone MDTM and MLSD use). `Mon d yyyy`, `d Mon yyyy` → midnight UTC (day resolution); `Mon d hh:mm`, `d Mon hh:mm` → the latest year not more than a day ahead of now; `yyyy-mm-dd hh:mm` (`-` or `/`) → as written. Anything else (non-English months, Japanese forms, impossible dates, ambiguous numeric forms) throws `EFTPLISTDATE` rather than inventing a timestamp. Cache validation compares exact instants, so a listing that switches from the time form to the year form simply redownloads. The security-patched `basic-ftp` override is unchanged.+## Inline Audit Policy`audit=false` is pinned in the same five `.npmrc` files, enforced by the same discovered-workspace test. This turns off only the advisory lookup `npm install` performs *after* it has already resolved and written `node_modules` — it does not change what gets installed.diff --git a/scripts/lib/getUriFtpPatch.js b/scripts/lib/getUriFtpPatch.jsnew file mode 100644index 0000000000..fc7f860c86--- /dev/null+++ b/scripts/lib/getUriFtpPatch.js@@ -0,0 +1,112 @@+/**+ * Install-time patch for get-uri's FTP adapter (#9462).+ *+ * get-uri decides "does this file exist, and when did it change" from+ * `client.lastMod()` (MDTM), then falls back to `client.list()` and reads+ * `entry.modifiedAt`. basic-ftp only fills `modifiedAt` from MLSD; its Unix+ * `LIST` parser sets `rawModifiedAt` and nothing else. A server without MDTM+ * *and* without MLSD therefore makes an existing file look missing (ENOTFOUND).+ * Upstream get-uri (through 8.0.1) still reads only `modifiedAt`, so we carry+ * the fallback ourselves. `ignore-scripts=true` blocks a postinstall hook, so+ * this runs from scripts/trusted-rebuilds.js — the same place every managed+ * install path already calls — against each workspace's installed tree.+ *+ * Raw date contract (basic-ftp `parseListUnix.js`): `rawModifiedAt` is+ * `"<date> <year-or-time>"`, one of+ * `Mon d yyyy` / `Mon d hh:mm` (ls -l: year for old files, time for recent)+ * `d Mon yyyy` / `d Mon hh:mm`+ * `yyyy-mm-dd hh:mm` (also with `/`)+ * LIST carries no timezone. We read every value as UTC, the same zone MDTM and+ * MLSD use, so the result is deterministic and never depends on the host's+ * locale. A year-less value (`Mon d hh:mm`) takes the most recent year that+ * does not put the date more than a day in the future. The year form has day+ * resolution only, so it is midnight UTC. Anything else (non-English month+ * names, Japanese forms, an out-of-range day) throws `EFTPLISTDATE` rather+ * than inventing a timestamp. Cache validation compares exact instants, so a+ * listing that later flips from the time form to the year form just redownloads.+ */+import { createHash } from 'crypto';+import { existsSync, readFileSync, writeFileSync } from 'fs';+import { join } from 'path';++export const GET_URI_PATCH_TARGET_VERSION = '6.0.5';+export const GET_URI_PATCH_MARKER = '/* portos-patch #9462: unix LIST modified date */';++const ANCHOR = 'lastModified = entry.modifiedAt;';+const HELPER_ANCHOR = 'const ftp = ';+const PATCHED = 'lastModified = entry.modifiedAt ?? parseUnixListDate(entry.rawModifiedAt);';++/**+ * Self-contained on purpose: `applyGetUriFtpPatch` injects this function's own+ * source into get-uri's CommonJS file, so it may reference nothing outside its body.+ * Returns a Date, or throws an Error with code `EFTPLISTDATE`.+ */+export function parseUnixListDate(raw, now = Date.now()) {+ const MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];+ const fail = () => Object.assign(+ new Error(`Unsupported FTP LIST modified date ${JSON.stringify(String(raw))}`),+ { code: 'EFTPLISTDATE' }+ );+ const build = (year, month, day, hour, minute) => {+ const date = new Date(Date.UTC(year, month, day, hour, minute));+ // Date.UTC rolls Feb 30 into March; a round-trip mismatch means the input was invalid.+ const valid = hour < 24 && minute < 60 && date.getUTCFullYear() === year+ && date.getUTCMonth() === month && date.getUTCDate() === day;+ return valid ? date : null;+ };+ const text = String(raw ?? '').trim();+ let month;+ let day;+ let tail;+ let match = text.match(/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})\s+(\d{1,2}):(\d{2})$/);+ if (match) {+ const date = build(+match[1], +match[2] - 1, +match[3], +match[4], +match[5]);+ if (!date) throw fail();+ return date;+ }+ if ((match = text.match(/^([A-Za-z]{3})\s+(\d{1,2})\s+(\d{4}|\d{1,2}:\d{2})$/))) {+ [, month, day, tail] = match;+ } else if ((match = text.match(/^(\d{1,2})\s+([A-Za-z]{3})\s+(\d{4}|\d{1,2}:\d{2})$/))) {+ [, day, month, tail] = match;+ } else {+ throw fail();+ }+ const monthIndex = MONTHS.indexOf(month.toLowerCase());+ if (monthIndex === -1) throw fail();+ if (!tail.includes(':')) {+ const date = build(+tail, monthIndex, +day, 0, 0);+ if (!date) throw fail();+ return date;+ }+ const [hour, minute] = tail.split(':').map(Number);+ const limit = now + 24 * 60 * 60 * 1000;+ // Walk back a few years so Feb 29 resolves to the latest leap year instead of failing.+ for (let year = new Date(limit).getUTCFullYear(), i = 0; i < 5; i += 1, year -= 1) {+ const date = build(year, monthIndex, +day, hour, minute);+ if (date && +date <= limit) return date;+ }+ throw fail();+}++/**+ * Patch `<nodeModulesDir>/get-uri/dist/ftp.js` in place. Idempotent. Returns+ * `absent` (get-uri not installed here), `patched`, `already-patched`, or+ * `unrecognized` (a get-uri this patch was not written for — never edited blind).+ */+export function applyGetUriFtpPatch(nodeModulesDir) {+ const file = join(nodeModulesDir, 'get-uri', 'dist', 'ftp.js');+ if (!existsSync(file)) return 'absent';+ const source = readFileSync(file, 'utf8');+ if (source.includes(GET_URI_PATCH_MARKER)) return 'already-patched';+ if (!source.includes(ANCHOR) || !source.includes(HELPER_ANCHOR)) return 'unrecognized';+ const helper = `${GET_URI_PATCH_MARKER}\n${parseUnixListDate.toString()}\n`;+ const patched = source.replace(ANCHOR, PATCHED).replace(HELPER_ANCHOR, `${helper}${HELPER_ANCHOR}`);+ writeFileSync(file, patched);+ return 'patched';+}++/** Changes whenever the injected code or its target does — see trusted-rebuild-stamp.js. */+export const patchFingerprint = () => createHash('sha256')+ .update([GET_URI_PATCH_TARGET_VERSION, ANCHOR, PATCHED, parseUnixListDate.toString()].join('\0'))+ .digest('hex')+ .slice(0, 16);diff --git a/scripts/lib/getUriFtpPatch.test.js b/scripts/lib/getUriFtpPatch.test.jsnew file mode 100644index 0000000000..c47f8f2193--- /dev/null+++ b/scripts/lib/getUriFtpPatch.test.js@@ -0,0 +1,110 @@+import { afterEach, describe, expect, it } from 'vitest';+import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';+import { createRequire } from 'module';+import { tmpdir } from 'os';+import { join } from 'path';++import {+ GET_URI_PATCH_MARKER,+ applyGetUriFtpPatch,+ parseUnixListDate,+ patchFingerprint+} from './getUriFtpPatch.js';++const NOW = Date.UTC(2026, 9, 1, 12, 0); // 2026-10-01T12:00Z+const iso = raw => parseUnixListDate(raw, NOW).toISOString();++describe('parseUnixListDate (basic-ftp rawModifiedAt contract, read as UTC)', () => {+ it.each([+ ['Jan 1 2020', '2020-01-01T00:00:00.000Z'],+ ['1 Jan 2020', '2020-01-01T00:00:00.000Z'],+ ['sep 09 2019', '2019-09-09T00:00:00.000Z'],+ ['2020-01-02 03:04', '2020-01-02T03:04:00.000Z'],+ ['2020/1/2 3:04', '2020-01-02T03:04:00.000Z'],+ ['Aug 15 08:30', '2026-08-15T08:30:00.000Z'],+ ['15 Aug 08:30', '2026-08-15T08:30:00.000Z']+ ])('parses %s', (raw, expected) => {+ expect(iso(raw)).toBe(expected);+ });++ it('resolves a year-less date to the latest year not beyond one day ahead', () => {+ expect(iso('Oct 1 11:59')).toBe('2026-10-01T11:59:00.000Z'); // earlier today+ expect(iso('Oct 2 11:00')).toBe('2026-10-02T11:00:00.000Z'); // within the skew tolerance+ expect(iso('Oct 3 00:00')).toBe('2025-10-03T00:00:00.000Z'); // beyond it: last year+ expect(iso('Dec 25 10:00')).toBe('2025-12-25T10:00:00.000Z');+ });++ it('finds the latest leap year for a year-less Feb 29', () => {+ expect(iso('Feb 29 10:00')).toBe('2024-02-29T10:00:00.000Z');+ });++ it.each([+ ['empty', ''],+ ['non-English month', 'Okt 1 2020'],+ ['Japanese form', '10月01日 2020年'],+ ['impossible day', 'Feb 30 2020'],+ ['impossible time', 'Jan 1 24:00'],+ ['ambiguous day-first numeric date', '01-02-2020 10:00'],+ ['trailing text', 'Jan 1 2020 extra']+ ])('refuses %s instead of inventing a timestamp', (_name, raw) => {+ expect(() => parseUnixListDate(raw, NOW)).toThrowError(expect.objectContaining({ code: 'EFTPLISTDATE' }));+ });+});++describe('applyGetUriFtpPatch', () => {+ const dirs = [];+ afterEach(() => dirs.splice(0).forEach(dir => rmSync(dir, { recursive: true, force: true })));++ // Reduced to the line the patch edits, plus the declaration it anchors on.+ const UPSTREAM = [+ '"use strict";',+ 'const ftp = (entry) => {',+ ' let lastModified;',+ ' if (entry) {',+ ' lastModified = entry.modifiedAt;',+ ' }',+ ' return lastModified;',+ '};',+ 'exports.ftp = ftp;',+ ''+ ].join('\n');++ const install = (source = UPSTREAM) => {+ const nodeModules = mkdtempSync(join(tmpdir(), 'get-uri-patch-'));+ dirs.push(nodeModules);+ mkdirSync(join(nodeModules, 'get-uri', 'dist'), { recursive: true });+ writeFileSync(join(nodeModules, 'get-uri', 'dist', 'ftp.js'), source);+ return nodeModules;+ };++ it('prefers MLSD/MDTM metadata and falls back to the parsed LIST date', () => {+ const nodeModules = install();+ expect(applyGetUriFtpPatch(nodeModules)).toBe('patched');+ const { ftp } = createRequire(import.meta.url)(join(nodeModules, 'get-uri', 'dist', 'ftp.js'));+ expect(ftp({ modifiedAt: new Date(0), rawModifiedAt: 'Jan 1 2020' })).toEqual(new Date(0));+ expect(ftp({ rawModifiedAt: 'Jan 1 2020' })).toEqual(new Date('2020-01-01T00:00:00Z'));+ expect(() => ftp({ rawModifiedAt: '' })).toThrowError(expect.objectContaining({ code: 'EFTPLISTDATE' }));+ });++ it('is idempotent', () => {+ const nodeModules = install();+ applyGetUriFtpPatch(nodeModules);+ const once = readFileSync(join(nodeModules, 'get-uri', 'dist', 'ftp.js'), 'utf8');+ expect(applyGetUriFtpPatch(nodeModules)).toBe('already-patched');+ expect(readFileSync(join(nodeModules, 'get-uri', 'dist', 'ftp.js'), 'utf8')).toBe(once);+ expect(once.split(GET_URI_PATCH_MARKER)).toHaveLength(2);+ });++ it('reports a missing install and never edits a get-uri it does not recognize', () => {+ expect(applyGetUriFtpPatch(mkdtempSync(join(tmpdir(), 'get-uri-empty-')))).toBe('absent');+ const foreign = 'module.exports = { ftp() { return entry.lastModified; } };\n';+ const nodeModules = install(foreign);+ expect(applyGetUriFtpPatch(nodeModules)).toBe('unrecognized');+ expect(readFileSync(join(nodeModules, 'get-uri', 'dist', 'ftp.js'), 'utf8')).toBe(foreign);+ });++ it('exposes a stable fingerprint so a cached node_modules tree can be invalidated', () => {+ expect(patchFingerprint()).toMatch(/^[0-9a-f]{16}$/);+ expect(patchFingerprint()).toBe(patchFingerprint());+ });+});diff --git a/scripts/trusted-rebuild-stamp.js b/scripts/trusted-rebuild-stamp.jsindex 9c73090075..011b50cb63 100644--- a/scripts/trusted-rebuild-stamp.js+++ b/scripts/trusted-rebuild-stamp.js@@ -34,6 +34,7 @@ import { existsSync, readFileSync, writeFileSync } from 'fs';import { join } from 'path';import { isDirectlyInvoked } from './lib/directInvocation.js';+import { patchFingerprint } from './lib/getUriFtpPatch.js';import { TRUSTED_REBUILDS, discoverWorkspaces, workspaceDir } from './trusted-rebuilds.js';export const STAMP_FILE = '.portos-trusted-rebuild.json';@@ -50,6 +51,9 @@ export function expectedStamp(label, { platform = process.platform, arch = procereturn {label,allowlist: createHash('sha256').update(JSON.stringify(TRUSTED_REBUILDS[label] ?? null)).digest('hex').slice(0, 16),+ // Install-time dependency patches are applied by the same step that writes+ // this mark, so a cached tree from before a patch changed must read as stale.+ patches: patchFingerprint(),platform,arch,modules: String(modules),diff --git a/scripts/trusted-rebuilds.js b/scripts/trusted-rebuilds.jsindex 97eb8d53fa..71154bb54d 100644--- a/scripts/trusted-rebuilds.js+++ b/scripts/trusted-rebuilds.js@@ -23,6 +23,7 @@ import { join, dirname } from 'path';import { fileURLToPath } from 'url';import { prepareCliSpawn } from '../server/lib/bufferedSpawn.js';import { isDirectlyInvoked } from './lib/directInvocation.js';+import { applyGetUriFtpPatch } from './lib/getUriFtpPatch.js';const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');@@ -79,6 +80,26 @@ export const TRUSTED_REBUILDS = {]};+/**+ * Apply PortOS's install-time dependency patches to one workspace's installed+ * tree (get-uri's FTP adapter, #9462 — see scripts/lib/getUriFtpPatch.js). Rides+ * on this module because every managed install path already calls it after+ * `npm install` and `ignore-scripts=true` rules out a postinstall hook. Never+ * fatal: the FTP fallback is a compatibility fix, not a boot requirement, and a+ * get-uri release this patch does not recognize is reported rather than edited.+ */+export function patchInstalledDependencies(dir) {+ try {+ const status = applyGetUriFtpPatch(join(dir, 'node_modules'));+ if (status === 'patched') console.log(`🩹 Patched get-uri FTP LIST date fallback in ${dir}`);+ if (status === 'unrecognized') {+ console.warn(`⚠️ get-uri in ${dir} is not the release the FTP LIST date patch targets — left unpatched (#9462)`);+ }+ } catch (err) {+ console.warn(`⚠️ get-uri FTP LIST date patch failed in ${dir}: ${err.message ?? err}`);+ }+}+/*** Rebuild the trusted packages for one workspace.* Returns true when every fatal group succeeded.@@ -90,6 +111,7 @@ export const TRUSTED_REBUILDS = {* than only a shape assertion on TRUSTED_REBUILDS.*/export function rebuildTrusted(dir, label, { spawn = execFileSync } = {}) {+ patchInstalledDependencies(dir);const groups = TRUSTED_REBUILDS[label];if (!groups) return true;let ok = true;@@ -139,7 +161,11 @@ export function runCli(argv, { spawn = execFileSync } = {}) {console.error(`❌ unknown workspace '${label}'. Known workspaces: ${workspaces.join(', ')}`);return 1;}+ // pm2 (and with it get-uri) installs in the repo root, which no setup/update+ // path rebuilds directly — the server step is the one hook all of them share.+ if (label === 'server' && !dirOverride) patchInstalledDependencies(ROOT);if (!TRUSTED_REBUILDS[label]) {+ patchInstalledDependencies(dirOverride ?? workspaceDir(label));console.log(`✅ no trusted rebuilds needed for ${label}`);return 0;}diff --git a/scripts/trusted-rebuilds.test.js b/scripts/trusted-rebuilds.test.jsindex 2acedc0eda..2bdb334202 100644--- a/scripts/trusted-rebuilds.test.js+++ b/scripts/trusted-rebuilds.test.js@@ -319,6 +319,40 @@ describe('npm spawn shape', () => {});});+describe('install-time dependency patch wiring (#9462)', () => {+ // The patch itself is covered in scripts/lib/getUriFtpPatch.test.js; this pins+ // that every managed install path (rebuildTrusted for any workspace, and the+ // rebuild-free CLI branch) actually reaches it.+ const upstream = 'const ftp = async () => {\n lastModified = entry.modifiedAt;\n};\n';+ const tree = () => {+ const dir = mkdtempSync(join(tmpdir(), 'trusted-patch-'));+ mkdirSync(join(dir, 'node_modules', 'get-uri', 'dist'), { recursive: true });+ writeFileSync(join(dir, 'node_modules', 'get-uri', 'dist', 'ftp.js'), upstream);+ return dir;+ };+ const patched = (dir) => readFileSync(join(dir, 'node_modules', 'get-uri', 'dist', 'ftp.js'), 'utf8').includes('parseUnixListDate');++ it('patches a workspace tree from rebuildTrusted even when it has no rebuilds', () => {+ const dir = tree();+ try {+ expect(rebuildTrusted(dir, 'client', { spawn: () => {} })).toBe(true);+ expect(patched(dir)).toBe(true);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });++ it('patches from the rebuild-free CLI branch too', () => {+ const dir = tree();+ try {+ expect(runCli(['browser', dir], { spawn: () => {} })).toBe(0);+ expect(patched(dir)).toBe(true);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });+});+describe('runCli exit codes', () => {const noop = () => {};diff --git a/server/dependency-overrides.test.js b/server/dependency-overrides.test.jsindex 99015de427..f04578fab7 100644--- a/server/dependency-overrides.test.js+++ b/server/dependency-overrides.test.js@@ -4,6 +4,7 @@ import { readFileSync } from 'fs';import { fileURLToPath } from 'url';import { dirname, join } from 'path';import { discoverWorkspaces } from '../scripts/trusted-rebuilds.js';+import { GET_URI_PATCH_TARGET_VERSION } from '../scripts/lib/getUriFtpPatch.js';const __dirname = dirname(fileURLToPath(import.meta.url));const REPO_ROOT = join(__dirname, '..');@@ -185,6 +186,18 @@ describe('dependency override parity across manifests (#2848)', () => {);});+ // scripts/lib/getUriFtpPatch.js edits get-uri's dist/ftp.js by exact anchor. A+ // lockfile move to another get-uri would leave installs unpatched (the patcher+ // skips a release it does not recognize), so the bump must re-verify the anchor.+ it.each(['package.json', 'server/package.json'])('%s resolves the get-uri release the FTP LIST date patch targets (#9462)', rel => {+ const resolved = Object.entries(readLockPackages(lockfileFor(rel)))+ .filter(([path]) => packageNameFromLockPath(path) === 'get-uri');+ expect(resolved.length).toBeGreaterThan(0);+ expect(resolved.map(([, metadata]) => metadata.version)).toEqual(+ resolved.map(() => GET_URI_PATCH_TARGET_VERSION)+ );+ });+it('governs every workspace manifest that ships its own lockfile', () => {const tracked = trackedLockfiles();const ungoverned = discoverWorkspaces()diff --git a/server/getUriFtp.test.js b/server/getUriFtp.test.jsindex 4d27941d2c..1b2a538b96 100644--- a/server/getUriFtp.test.js+++ b/server/getUriFtp.test.js@@ -13,7 +13,9 @@ afterEach(async () => {}));});-const startFtp = async (mdtmResponse) => {+// `unixLine` swaps MLSD for a Unix `ls -l` LIST (no MLST in FEAT), the shape a+// legacy server without MDTM/MLSD returns. Its date is the only metadata offered.+const startFtp = async (mdtmResponse, { unixLine } = {}) => {const commands = [];const servers = [];const sockets = new Set();@@ -44,7 +46,7 @@ const startFtp = async (mdtmResponse) => {const verb = line.split(' ')[0];if (verb === 'USER') control.write('331 Password required\r\n');else if (verb === 'PASS') control.write('230 Logged in\r\n');- else if (verb === 'FEAT') control.write('211-Features\r\n UTF8\r\n MLST type*;size*;modify*;\r\n211 End\r\n');+ else if (verb === 'FEAT') control.write(`211-Features\r\n UTF8\r\n${unixLine ? '' : ' MLST type*;size*;modify*;\r\n'}211 End\r\n`);else if (verb === 'MDTM') control.write(`${mdtmResponse}\r\n`);else if (verb === 'EPSV') {passiveServer = createServer();@@ -55,9 +57,8 @@ const startFtp = async (mdtmResponse) => {});} else if (verb === 'MLSD' || verb === 'LIST' || verb === 'RETR') {control.write('150 Opening data connection\r\n');- const payload = verb !== 'RETR'- ? 'type=file;size=19;modify=20200101000000; example.txt\r\n'- : 'synthetic download\n';+ const listing = unixLine ?? 'type=file;size=19;modify=20200101000000; example.txt';+ const payload = verb !== 'RETR' ? `${listing}\r\n` : 'synthetic download\n';dataConnection.then(socket => {socket.end(payload, () => {control.write('226 Transfer complete\r\n');@@ -103,6 +104,43 @@ describe('get-uri FTP compatibility with the security override (#9444)', () => {expect(ftp.commands.some(command => command.startsWith('RETR'))).toBe(false);});+ const unixLine = date => `-rw-r--r-- 1 owner group 19 ${date} example.txt`;+ const utcMonthDayTime = date => `${date.toLocaleString('en-US', { month: 'short', timeZone: 'UTC' })} ${date.getUTCDate()} `+ + `${String(date.getUTCHours()).padStart(2, '0')}:${String(date.getUTCMinutes()).padStart(2, '0')}`;+ const recent = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);+ recent.setUTCSeconds(0, 0);++ it.each([+ ['year form (day resolution, UTC midnight)', unixLine('Jan 1 2020'), new Date('2020-01-01T00:00:00Z')],+ ['recent time form (year inferred)', unixLine(utcMonthDayTime(recent)), recent]+ ])('downloads an existing file when MDTM is unsupported and only a Unix LIST date exists: %s (#9462)', async (_name, line, expected) => {+ const ftp = await startFtp('502 MDTM unsupported', { unixLine: line });+ const stream = await getUri(ftp.url);+ expect(await readStream(stream)).toBe('synthetic download\n');+ expect(stream.lastModified).toEqual(expected);+ await ftp.sessions[0];+ expect(ftp.commands.some(command => command.startsWith('MLSD'))).toBe(false);+ expect(ftp.commands.some(command => command.startsWith('LIST'))).toBe(true);+ ftp.commands.length = 0;+ await expect(getUri(ftp.url, { cache: stream })).rejects.toMatchObject({ code: 'ENOTMODIFIED' });+ await ftp.sessions[1];+ expect(ftp.commands.some(command => command.startsWith('RETR'))).toBe(false);+ });++ it('fails clearly, without downloading, when the Unix LIST date is not a supported format (#9462)', async () => {+ const ftp = await startFtp('502 MDTM unsupported', { unixLine: unixLine('Okt 1 2020') });+ await expect(getUri(ftp.url)).rejects.toMatchObject({ code: 'EFTPLISTDATE' });+ await ftp.sessions[0];+ expect(ftp.commands.some(command => command.startsWith('RETR'))).toBe(false);+ });++ it('reports a file absent from a Unix LIST as missing without downloading (#9462)', async () => {+ const ftp = await startFtp('502 MDTM unsupported', { unixLine: unixLine('Jan 1 2020').replace('example.txt', 'other.txt') });+ await expect(getUri(ftp.url)).rejects.toMatchObject({ code: 'ENOTFOUND' });+ await ftp.sessions[0];+ expect(ftp.commands.some(command => command.startsWith('RETR'))).toBe(false);+ });+it('reports missing files without listing or downloading and closes the connection', async () => {const ftp = await startFtp('550 File missing');await expect(getUri(ftp.url)).rejects.toMatchObject({ code: 'ENOTFOUND' });