aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/assistant/test_files.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-16 16:20:01 +0200
committerDanilo M. <danix@danix.xyz>2026-10-16 16:20:01 +0200
commit12d6830424d24f5a2ed8056b53a12cc4b978ece2 (patch)
treea52a30ab446acd718aa67e1c8dc2887a472954cb /desktop/assistant/test_files.js
parentf6ceae477979b32869c0c17e2b1fc05477d6eb81 (diff)
downloadquickshell-12d6830424d24f5a2ed8056b53a12cc4b978ece2.tar.gz
quickshell-12d6830424d24f5a2ed8056b53a12cc4b978ece2.zip
feat(assistant): tell a nameless file's kind from its content
A script with no suffix staged as 'other' and was refused. A staged file the name says nothing about is now handed to file(1) once, and its mime type gives the kind, so a shell script is code and gets Explain and Review. The daemon makes its own call on the content. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/assistant/test_files.js')
-rw-r--r--desktop/assistant/test_files.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/desktop/assistant/test_files.js b/desktop/assistant/test_files.js
index 80a855d..f2a65ca 100644
--- a/desktop/assistant/test_files.js
+++ b/desktop/assistant/test_files.js
@@ -18,7 +18,7 @@ const assert = require("assert");
const src = fs.readFileSync(__dirname + "/Files.js", "utf8")
.replace(/^\.pragma library$/m, "");
-const F = new Function(src + "\nreturn { kind, chats, fromUrl, file, name };")();
+const F = new Function(src + "\nreturn { kind, chats, fromUrl, file, name, fromMime };")();
const cases = {
"/a/report.pdf": "pdf", "/a/Report.PDF": "pdf", "/a/x.png": "image", "/a/x.JPEG": "image",
@@ -40,4 +40,14 @@ assert.strictEqual(F.fromUrl("file://otherhost/tmp/a.pdf"), "");
assert.strictEqual(F.fromUrl("file:///bad%E0%A4%A"), ""); // malformed escape
assert.deepStrictEqual(F.file("/x/y/a b.pdf"), { path: "/x/y/a b.pdf", name: "a b.pdf", kind: "pdf" });
+// A file the name says nothing about is told by its mime type (file -b).
+const mimes = {
+ "text/x-shellscript": "code", "text/x-script.python": "code", "text/x-c": "code",
+ "text/x-makefile": "code", "application/json": "code", "text/plain": "text",
+ "text/csv": "text", "text/markdown": "text", "image/png": "image", "application/pdf": "pdf",
+ "video/mp4": "video", "application/zip": "archive", "application/x-xz": "archive",
+ "application/octet-stream": "other", "application/x-executable": "other", "": "other",
+};
+for (const [m, k] of Object.entries(mimes)) assert.strictEqual(F.fromMime(m), k, m);
+
console.log("ok");