-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtokens.test.ts
More file actions
79 lines (68 loc) · 2.87 KB
/
tokens.test.ts
File metadata and controls
79 lines (68 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { describe, expect, test } from "bun:test";
import {
isFileWithinTimeRange,
pathToProjectSlug,
} from "../src/commands/session/tokens.js";
describe("pathToProjectSlug", () => {
test("encodes absolute paths to claude's slug form", () => {
expect(pathToProjectSlug("/workspaces/projects/CodeForge")).toBe(
"-workspaces-projects-CodeForge",
);
});
test("encodes dotfiles with double dashes like claude does", () => {
// /workspaces/.devcontainer -> /workspaces/-devcontainer (slash -> dash,
// then the leading dot on the next segment becomes another dash)
expect(pathToProjectSlug("/workspaces/.devcontainer")).toBe(
"-workspaces--devcontainer",
);
});
test("strips trailing slashes before encoding", () => {
expect(pathToProjectSlug("/workspaces/projects/CodeForge/")).toBe(
"-workspaces-projects-CodeForge",
);
expect(pathToProjectSlug("/workspaces/projects/CodeForge///")).toBe(
"-workspaces-projects-CodeForge",
);
});
test("passes plain substrings through unchanged for backwards compat", () => {
// No separator -> user wants substring match against a slug
expect(pathToProjectSlug("CodeForge")).toBe("CodeForge");
expect(pathToProjectSlug("projects-CodeForge")).toBe("projects-CodeForge");
});
test("resolves relative ./ and ../ paths before encoding", () => {
const abs = pathToProjectSlug("./foo");
// Resolved path always ends with /foo; after encoding trailing segment is -foo
expect(abs.endsWith("-foo")).toBe(true);
// On POSIX, resolved absolute paths start with `/` which encodes to `-`.
// On Windows they start with a drive letter (e.g. `D:`) so the leading
// `-` assertion is POSIX-only.
if (process.platform !== "win32") {
expect(abs.startsWith("-")).toBe(true);
}
const abs2 = pathToProjectSlug("../bar");
expect(abs2.endsWith("-bar")).toBe(true);
});
});
describe("isFileWithinTimeRange", () => {
const jan1 = new Date("2026-01-01T00:00:00Z");
const feb1 = new Date("2026-02-01T00:00:00Z");
const mar1 = new Date("2026-03-01T00:00:00Z");
test("returns true when no bounds are given", () => {
expect(isFileWithinTimeRange(feb1)).toBe(true);
});
test("since: includes mtimes at or after the bound", () => {
expect(isFileWithinTimeRange(feb1, jan1)).toBe(true);
expect(isFileWithinTimeRange(feb1, feb1)).toBe(true); // inclusive
expect(isFileWithinTimeRange(feb1, mar1)).toBe(false);
});
test("until: includes mtimes at or before the bound", () => {
expect(isFileWithinTimeRange(feb1, undefined, mar1)).toBe(true);
expect(isFileWithinTimeRange(feb1, undefined, feb1)).toBe(true); // inclusive
expect(isFileWithinTimeRange(feb1, undefined, jan1)).toBe(false);
});
test("since + until: inclusive range", () => {
expect(isFileWithinTimeRange(feb1, jan1, mar1)).toBe(true);
expect(isFileWithinTimeRange(jan1, feb1, mar1)).toBe(false);
expect(isFileWithinTimeRange(mar1, jan1, feb1)).toBe(false);
});
});