Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(scripts): check-cloud-sales finds docs/ in a path with a space

purple43dbd8f05f68
diff --git a/scripts/check-cloud-sales.mjs b/scripts/check-cloud-sales.mjs
index d4e435a3..8b97c573 100644
--- a/scripts/check-cloud-sales.mjs
+++ b/scripts/check-cloud-sales.mjs
@@ -3,6 +3,7 @@
import assert from 'node:assert/strict'
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
import { resolve, isAbsolute } from 'node:path'
+import { fileURLToPath } from 'node:url'
import ts from 'typescript'
import { JSDOM } from 'jsdom'
@@ -48,7 +49,9 @@ function docsFiles(dir, out = []) {
}
return out
}
-const docsRoot = new URL('../docs', import.meta.url).pathname
+// fileURLToPath, not .pathname: the URL keeps a space as %20, and a
+// checkout under "Locally Uncensored" then has no docs folder.
+const docsRoot = fileURLToPath(new URL('../docs', import.meta.url))
const page = new JSDOM(readFileSync(new URL('../docs/cloud/index.html', import.meta.url), 'utf8')).window.document
const catalog = objects(source('apps/web/lib/chat/tier-models.ts'))
diff --git a/src/lib/__tests__/script-paths-with-spaces.test.ts b/src/lib/__tests__/script-paths-with-spaces.test.ts
new file mode 100644
index 00000000..0aee7228
--- /dev/null
+++ b/src/lib/__tests__/script-paths-with-spaces.test.ts
@@ -0,0 +1,33 @@
+/**
+ * The repository is checked out under "Locally Uncensored", with a space.
+ * `new URL(…, import.meta.url).pathname` keeps that space as %20, so a script
+ * that builds a folder path that way finds nothing (check-cloud-sales.mjs did,
+ * 3.1.0). Scripts turn file URLs into paths with fileURLToPath.
+ */
+import { describe, expect, it } from 'vitest'
+import { readFileSync, readdirSync } from 'node:fs'
+import { resolve, join } from 'node:path'
+import { fileURLToPath, pathToFileURL } from 'node:url'
+
+const SCRIPTS = resolve('scripts')
+const files = (dir: string): string[] =>
+ readdirSync(dir, { withFileTypes: true }).flatMap((e) =>
+ e.isDirectory() ? (e.name === 'node_modules' ? [] : files(join(dir, e.name))) : /\.(mjs|cjs|js|ts)$/.test(e.name) ? [join(dir, e.name)] : [])
+
+describe('scripts read their own folder in a path with a space', () => {
+ it('no script takes .pathname of a file URL', () => {
+ const hits = files(SCRIPTS).filter((f) => /import\.meta\.url\)\s*\.pathname/.test(readFileSync(f, 'utf8')))
+ expect(hits.map((f) => f.slice(SCRIPTS.length + 1))).toEqual([])
+ })
+
+ it('fileURLToPath gives the real folder where .pathname does not', () => {
+ const dir = '/tmp/Locally Uncensored/docs'
+ const url = pathToFileURL(dir)
+ expect(url.pathname).toContain('%20')
+ expect(fileURLToPath(url)).toBe(dir)
+ })
+
+ it('check-cloud-sales finds the docs folder with fileURLToPath', () => {
+ expect(readFileSync(join(SCRIPTS, 'check-cloud-sales.mjs'), 'utf8')).toMatch(/const docsRoot = fileURLToPath\(new URL\('\.\.\/docs', import\.meta\.url\)\)/)
+ })
+})