@zyro-sec/util 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/layer-node.md +155 -0
- package/package.json +12 -19
- package/script/build.ts +9 -0
- package/script/pack.ts +5 -0
- package/src/abort.test.ts +16 -0
- package/src/abort.ts +9 -0
- package/src/activity-calendar.test.ts +136 -0
- package/src/activity-calendar.ts +50 -0
- package/src/artifact.test.ts +29 -0
- package/src/artifact.ts +95 -0
- package/src/base64.test.ts +12 -0
- package/src/base64.ts +29 -0
- package/src/binary.test.ts +19 -0
- package/src/binary.ts +30 -0
- package/src/bom.test.ts +21 -0
- package/src/bom.ts +46 -0
- package/src/cross-spawn-spawner.ts +694 -0
- package/src/duration.ts +22 -0
- package/src/effect/app-node-platform.ts +40 -0
- package/src/effect/app-node.ts +14 -0
- package/src/effect/layer-node.ts +360 -0
- package/src/effect-flock.ts +313 -0
- package/src/encode.test.ts +32 -0
- package/src/encode.ts +39 -0
- package/src/execute-output.test.ts +36 -0
- package/src/execute-output.ts +23 -0
- package/src/flock.ts +346 -0
- package/src/fs-util.ts +271 -0
- package/src/glob.ts +38 -0
- package/src/global-roots.ts +19 -0
- package/src/global-roots.workerd.ts +16 -0
- package/src/global.ts +88 -0
- package/src/hash.ts +11 -0
- package/src/heap-snapshot.ts +44 -0
- package/src/no-timeout-fetch.test.ts +33 -0
- package/src/no-timeout-fetch.ts +5 -0
- package/src/npm-config.ts +41 -0
- package/src/npm.ts +557 -0
- package/src/observability/logging.ts +179 -0
- package/src/observability/otlp.ts +109 -0
- package/src/observability/shared.ts +8 -0
- package/src/observability.ts +60 -0
- package/src/open.test.ts +16 -0
- package/src/open.ts +12 -0
- package/src/patch.ts +382 -0
- package/src/path.test.ts +89 -0
- package/src/path.ts +149 -0
- package/src/process-signal.test.ts +38 -0
- package/src/process-signal.ts +23 -0
- package/src/process.ts +270 -0
- package/src/qr.ts +323 -0
- package/src/record.ts +3 -0
- package/src/retry.test.ts +87 -0
- package/src/retry.ts +51 -0
- package/src/runtime/import.bun.ts +10 -0
- package/src/runtime/import.node.ts +61 -0
- package/src/runtime/import.workerd.ts +9 -0
- package/src/runtime-import.ts +1 -0
- package/src/session-mention.test.ts +19 -0
- package/src/session-mention.ts +24 -0
- package/src/session-title-fallback.ts +36 -0
- package/src/session-turn.test.ts +131 -0
- package/src/session-turn.ts +82 -0
- package/src/teardown.ts +19 -0
- package/src/text-boundary.test.ts +39 -0
- package/src/text-boundary.ts +36 -0
- package/src/uuid.test.ts +80 -0
- package/src/uuid.ts +15 -0
- package/test/fixtures/qr.json +625 -0
- package/test/glob.test.ts +11 -0
- package/test/global-roots.test.ts +62 -0
- package/test/global.test.ts +99 -0
- package/test/observability-otlp.test.ts +45 -0
- package/test/qr.test.ts +113 -0
- package/test/session-title-fallback.test.ts +49 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.dist.json +10 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import os from "os"
|
|
3
|
+
import path from "path"
|
|
4
|
+
import { pathToFileURL } from "url"
|
|
5
|
+
|
|
6
|
+
const module = pathToFileURL(path.join(import.meta.dir, "../src/global-roots.ts")).href
|
|
7
|
+
|
|
8
|
+
describe("global roots", () => {
|
|
9
|
+
test("uses XDG overrides", () => {
|
|
10
|
+
const root = path.join(os.tmpdir(), "opencode-xdg-overrides")
|
|
11
|
+
const env = {
|
|
12
|
+
XDG_DATA_HOME: path.join(root, "data"),
|
|
13
|
+
XDG_CACHE_HOME: path.join(root, "cache"),
|
|
14
|
+
XDG_CONFIG_HOME: path.join(root, "config"),
|
|
15
|
+
XDG_STATE_HOME: path.join(root, "state"),
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
expect(run(env)).toEqual({
|
|
19
|
+
data: path.join(env.XDG_DATA_HOME, "opencode"),
|
|
20
|
+
cache: path.join(env.XDG_CACHE_HOME, "opencode"),
|
|
21
|
+
config: path.join(env.XDG_CONFIG_HOME, "opencode"),
|
|
22
|
+
state: path.join(env.XDG_STATE_HOME, "opencode"),
|
|
23
|
+
tmp: path.join(os.tmpdir(), "opencode"),
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test("empty XDG overrides use home directory defaults", () => {
|
|
28
|
+
const home = path.join(os.tmpdir(), "opencode-xdg-home")
|
|
29
|
+
|
|
30
|
+
expect(
|
|
31
|
+
run({
|
|
32
|
+
XDG_DATA_HOME: "",
|
|
33
|
+
XDG_CACHE_HOME: "",
|
|
34
|
+
XDG_CONFIG_HOME: "",
|
|
35
|
+
XDG_STATE_HOME: "",
|
|
36
|
+
...(process.platform === "win32" ? { USERPROFILE: home } : { HOME: home }),
|
|
37
|
+
}),
|
|
38
|
+
).toEqual({
|
|
39
|
+
data: path.join(home, ".local", "share", "opencode"),
|
|
40
|
+
cache: path.join(home, ".cache", "opencode"),
|
|
41
|
+
config: path.join(home, ".config", "opencode"),
|
|
42
|
+
state: path.join(home, ".local", "state", "opencode"),
|
|
43
|
+
tmp: path.join(os.tmpdir(), "opencode"),
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
function run(env: Record<string, string>) {
|
|
49
|
+
const result = Bun.spawnSync({
|
|
50
|
+
cmd: [
|
|
51
|
+
process.execPath,
|
|
52
|
+
"-e",
|
|
53
|
+
`const { roots } = await import(${JSON.stringify(module)}); console.log(JSON.stringify(roots("opencode")))`,
|
|
54
|
+
],
|
|
55
|
+
env: { ...process.env, ...env },
|
|
56
|
+
stdout: "pipe",
|
|
57
|
+
stderr: "pipe",
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
expect(result.exitCode, result.stderr.toString()).toBe(0)
|
|
61
|
+
return JSON.parse(result.stdout.toString())
|
|
62
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import fs from "fs"
|
|
3
|
+
import os from "os"
|
|
4
|
+
import path from "path"
|
|
5
|
+
import { pathToFileURL } from "url"
|
|
6
|
+
import { Context, Effect, Layer } from "effect"
|
|
7
|
+
import { Global } from "../src/global.js"
|
|
8
|
+
|
|
9
|
+
describe("global", () => {
|
|
10
|
+
test("importing the module does not create directories", () => {
|
|
11
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-global-import-"))
|
|
12
|
+
const directories = ["data", "cache", "config", "state", "tmp"].map((directory) => path.join(root, directory))
|
|
13
|
+
const module = pathToFileURL(path.join(import.meta.dir, "../src/global.ts")).href
|
|
14
|
+
const result = Bun.spawnSync({
|
|
15
|
+
cmd: [process.execPath, "-e", `const { Global } = await import(${JSON.stringify(module)}); void Global.Path.tmp`],
|
|
16
|
+
env: {
|
|
17
|
+
...process.env,
|
|
18
|
+
XDG_DATA_HOME: directories[0],
|
|
19
|
+
XDG_CACHE_HOME: directories[1],
|
|
20
|
+
XDG_CONFIG_HOME: directories[2],
|
|
21
|
+
XDG_STATE_HOME: directories[3],
|
|
22
|
+
// os.tmpdir() reads TMPDIR on POSIX and TEMP on Windows.
|
|
23
|
+
TMPDIR: directories[4],
|
|
24
|
+
TEMP: directories[4],
|
|
25
|
+
},
|
|
26
|
+
stderr: "pipe",
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
expect(result.exitCode, result.stderr.toString()).toBe(0)
|
|
30
|
+
directories.forEach((directory) => expect(fs.existsSync(path.join(directory, "opencode"))).toBe(false))
|
|
31
|
+
fs.rmSync(root, { recursive: true, force: true })
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test("building layerWith creates service directories and preserves an explicit tmp", async () => {
|
|
35
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-global-layer-"))
|
|
36
|
+
const directories = {
|
|
37
|
+
data: path.join(root, "data"),
|
|
38
|
+
config: path.join(root, "config"),
|
|
39
|
+
state: path.join(root, "state"),
|
|
40
|
+
log: path.join(root, "log"),
|
|
41
|
+
bin: path.join(root, "bin"),
|
|
42
|
+
repos: path.join(root, "repos"),
|
|
43
|
+
tmp: path.join(root, "nested", "..", "tmp"),
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const context = await Effect.runPromise(Effect.scoped(Layer.build(Global.layerWith(directories))))
|
|
47
|
+
|
|
48
|
+
Object.values(directories).forEach((directory) => expect(fs.statSync(directory).isDirectory()).toBe(true))
|
|
49
|
+
expect(Context.get(context, Global.Service).tmp).toBe(directories.tmp)
|
|
50
|
+
fs.rmSync(root, { recursive: true, force: true })
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test("building a layer with default tmp creates and canonicalizes it", () => {
|
|
54
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-global-layer-"))
|
|
55
|
+
const directories = ["data", "cache", "config", "state", "tmp"].map((directory) => path.join(root, directory))
|
|
56
|
+
const module = pathToFileURL(path.join(import.meta.dir, "../src/global.ts")).href
|
|
57
|
+
const result = Bun.spawnSync({
|
|
58
|
+
cmd: [
|
|
59
|
+
process.execPath,
|
|
60
|
+
"-e",
|
|
61
|
+
`
|
|
62
|
+
import { Context, Effect, Layer } from "effect"
|
|
63
|
+
const { Global } = await import(${JSON.stringify(module)})
|
|
64
|
+
const context = await Effect.runPromise(Effect.scoped(Layer.build(Global.layerWith({}))))
|
|
65
|
+
process.stdout.write(Context.get(context, Global.Service).tmp)
|
|
66
|
+
`,
|
|
67
|
+
],
|
|
68
|
+
cwd: path.join(import.meta.dir, ".."),
|
|
69
|
+
env: {
|
|
70
|
+
...process.env,
|
|
71
|
+
XDG_DATA_HOME: directories[0],
|
|
72
|
+
XDG_CACHE_HOME: directories[1],
|
|
73
|
+
XDG_CONFIG_HOME: directories[2],
|
|
74
|
+
XDG_STATE_HOME: directories[3],
|
|
75
|
+
// os.tmpdir() reads TMPDIR on POSIX and TEMP on Windows.
|
|
76
|
+
TMPDIR: directories[4],
|
|
77
|
+
TEMP: directories[4],
|
|
78
|
+
},
|
|
79
|
+
stdout: "pipe",
|
|
80
|
+
stderr: "pipe",
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
expect(result.exitCode, result.stderr.toString()).toBe(0)
|
|
84
|
+
// The layer canonicalizes through the native realpath, which on Windows also expands 8.3 short
|
|
85
|
+
// names such as RUNNER~1 that the JavaScript realpathSync leaves in place.
|
|
86
|
+
expect(result.stdout.toString()).toBe(fs.realpathSync.native(path.join(directories[4], "opencode")))
|
|
87
|
+
const created = [
|
|
88
|
+
path.join(directories[0], "opencode"),
|
|
89
|
+
path.join(directories[1], "opencode", "bin"),
|
|
90
|
+
path.join(directories[2], "opencode"),
|
|
91
|
+
path.join(directories[3], "opencode"),
|
|
92
|
+
path.join(directories[0], "opencode", "log"),
|
|
93
|
+
path.join(directories[0], "opencode", "repos"),
|
|
94
|
+
path.join(directories[4], "opencode"),
|
|
95
|
+
]
|
|
96
|
+
created.forEach((directory) => expect(fs.statSync(directory).isDirectory()).toBe(true))
|
|
97
|
+
fs.rmSync(root, { recursive: true, force: true })
|
|
98
|
+
})
|
|
99
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { Effect } from "effect"
|
|
3
|
+
import { Otlp } from "../src/observability/otlp.js"
|
|
4
|
+
|
|
5
|
+
test("exports a span through the configured OTLP trace endpoint", async () => {
|
|
6
|
+
const requests: unknown[] = []
|
|
7
|
+
const headers: string[] = []
|
|
8
|
+
const paths: string[] = []
|
|
9
|
+
const server = Bun.serve({
|
|
10
|
+
hostname: "127.0.0.1",
|
|
11
|
+
port: 0,
|
|
12
|
+
async fetch(request) {
|
|
13
|
+
paths.push(new URL(request.url).pathname)
|
|
14
|
+
headers.push(request.headers.get("x-otel-test") ?? "")
|
|
15
|
+
requests.push(await request.json())
|
|
16
|
+
return Response.json({})
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
await Effect.gen(function* () {
|
|
22
|
+
const tracing = yield* Otlp.tracingLayer(
|
|
23
|
+
{ endpoint: server.url.origin, headers: "x-otel-test=present" },
|
|
24
|
+
{ client: "test", version: "1.0.0", channel: "local" },
|
|
25
|
+
)
|
|
26
|
+
yield* Effect.void.pipe(Effect.withSpan("otlp-smoke"), Effect.provide(tracing))
|
|
27
|
+
}).pipe(Effect.scoped, Effect.runPromise)
|
|
28
|
+
|
|
29
|
+
expect(requests).toHaveLength(1)
|
|
30
|
+
expect(paths).toEqual(["/v1/traces"])
|
|
31
|
+
expect(headers).toEqual(["present"])
|
|
32
|
+
expect(requests[0]).toMatchObject({
|
|
33
|
+
resourceSpans: [
|
|
34
|
+
{
|
|
35
|
+
resource: {
|
|
36
|
+
attributes: expect.arrayContaining([{ key: "service.name", value: { stringValue: "opencode" } }]),
|
|
37
|
+
},
|
|
38
|
+
scopeSpans: [{ spans: [expect.objectContaining({ name: "otlp-smoke" })] }],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
} finally {
|
|
43
|
+
server.stop(true)
|
|
44
|
+
}
|
|
45
|
+
})
|
package/test/qr.test.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { randomBytes } from "node:crypto"
|
|
3
|
+
import jsQR from "jsqr"
|
|
4
|
+
import { encode, renderSVG, renderUnicodeCompact } from "../src/qr.js"
|
|
5
|
+
import fixtures from "./fixtures/qr.json" with { type: "json" }
|
|
6
|
+
|
|
7
|
+
// Fixtures were generated once with the uqr package, a port of Nayuki's reference encoder. Each row is hex with a
|
|
8
|
+
// leading 1 bit so leading light modules survive.
|
|
9
|
+
const golden = fixtures.map((fixture) => ({
|
|
10
|
+
...fixture,
|
|
11
|
+
modules: fixture.rows.map((row) =>
|
|
12
|
+
[
|
|
13
|
+
...BigInt("0x" + row)
|
|
14
|
+
.toString(2)
|
|
15
|
+
.slice(1),
|
|
16
|
+
].map((bit) => bit === "1"),
|
|
17
|
+
),
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
describe("qr", () => {
|
|
21
|
+
test.each(golden.map((fixture) => [fixture.version, fixture.text.slice(0, 40), fixture] as const))(
|
|
22
|
+
"matches the reference encoder at version %i: %s",
|
|
23
|
+
(version, _, fixture) => {
|
|
24
|
+
const modules = encode(fixture.text)
|
|
25
|
+
expect(modules.length).toBe(version * 4 + 17)
|
|
26
|
+
expect(modules).toEqual(fixture.modules)
|
|
27
|
+
},
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
// jsQR 1.4.0 places version 23's alignment patterns at 74 instead of 78, so it can't read that version.
|
|
31
|
+
test.each(golden.filter((fixture) => fixture.version !== 23).map((fixture) => [fixture.version, fixture] as const))(
|
|
32
|
+
"SVG and terminal output decode at version %i",
|
|
33
|
+
(_, fixture) => {
|
|
34
|
+
expect(decode(fromSVG(renderSVG(fixture.text, { border: 4 })))).toBe(fixture.text)
|
|
35
|
+
expect(decode(fromUnicode(renderUnicodeCompact(fixture.text, { border: 1 })))).toBe(fixture.text)
|
|
36
|
+
},
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
test("random pairing payloads decode", () => {
|
|
40
|
+
Array.from({ length: 30 }, (_, i) => {
|
|
41
|
+
const text = JSON.stringify({
|
|
42
|
+
code: randomBytes(16).toString("base64url"),
|
|
43
|
+
urls: Array.from({ length: 1 + (i % 5) }, (_, j) => `http://192.168.${i}.${j + 1}:4096`),
|
|
44
|
+
})
|
|
45
|
+
expect(decode(fromUnicode(renderUnicodeCompact(text, { border: (i % 3) + 1 })))).toBe(text)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test("renders the SVG as uqr did", () => {
|
|
50
|
+
const svg = renderSVG("hello", { border: 4, blackColor: "currentColor", whiteColor: "transparent" })
|
|
51
|
+
expect(svg).toStartWith(
|
|
52
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 290 290"><rect fill="transparent" width="290" height="290"/><path fill="currentColor" d="M40,40h10v10h-10zM50,40h10v10h-10z',
|
|
53
|
+
)
|
|
54
|
+
expect(fromSVG(svg)).toEqual(withBorder(golden[0].modules, 4))
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test("renders terminal rows in pairs and shows the background below the last odd row", () => {
|
|
58
|
+
const lines = renderUnicodeCompact("hello", { border: 2 }).split("\n")
|
|
59
|
+
expect(lines).toHaveLength(13)
|
|
60
|
+
expect(lines.every((line) => line.length === 25)).toBe(true)
|
|
61
|
+
expect(lines[0]).toBe("\u2588".repeat(25))
|
|
62
|
+
expect(lines.at(-1)).toBe("\u2580".repeat(25))
|
|
63
|
+
expect(fromUnicode(lines.join("\n"))).toEqual(withBorder(golden[0].modules, 2))
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test("rejects text longer than version 40 holds", () => {
|
|
67
|
+
expect(encode("a".repeat(2953))).toHaveLength(177)
|
|
68
|
+
expect(() => encode("a".repeat(2954))).toThrow(RangeError)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
function withBorder(modules: boolean[][], border: number) {
|
|
73
|
+
const width = modules.length + border * 2
|
|
74
|
+
const light = Array<boolean>(border).fill(false)
|
|
75
|
+
const edge = Array.from({ length: border }, () => Array<boolean>(width).fill(false))
|
|
76
|
+
return [...edge, ...modules.map((row) => [...light, ...row, ...light]), ...edge]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function fromSVG(svg: string) {
|
|
80
|
+
const width = Number(svg.match(/viewBox="0 0 (\d+)/)?.[1]) / 10
|
|
81
|
+
const modules = Array.from({ length: width }, () => Array<boolean>(width).fill(false))
|
|
82
|
+
for (const match of svg.matchAll(/M(\d+),(\d+)h10v10h-10z/g))
|
|
83
|
+
modules[Number(match[2]) / 10][Number(match[1]) / 10] = true
|
|
84
|
+
return modules
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Reverses the half-block encoding and drops the padding row under the last line.
|
|
88
|
+
function fromUnicode(text: string) {
|
|
89
|
+
const lines = text.split("\n")
|
|
90
|
+
const halves = { "\u2588": [false, false], "\u2580": [false, true], "\u2584": [true, false], " ": [true, true] }
|
|
91
|
+
return lines
|
|
92
|
+
.flatMap((line) => {
|
|
93
|
+
const pairs = [...line].map((char) => halves[char as keyof typeof halves])
|
|
94
|
+
return [pairs.map((pair) => pair[0]), pairs.map((pair) => pair[1])]
|
|
95
|
+
})
|
|
96
|
+
.slice(0, lines[0].length)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Draws the modules 4 pixels each with an extra quiet zone, then reads them back with jsQR.
|
|
100
|
+
function decode(modules: boolean[][]) {
|
|
101
|
+
const scale = 4
|
|
102
|
+
const padded = withBorder(modules, 4)
|
|
103
|
+
const width = padded.length * scale
|
|
104
|
+
const pixels = new Uint8ClampedArray(width * width * 4).map((_, i) => {
|
|
105
|
+
if (i % 4 === 3) return 255
|
|
106
|
+
const pixel = Math.floor(i / 4)
|
|
107
|
+
return padded[Math.floor(pixel / width / scale)][Math.floor((pixel % width) / scale)] ? 0 : 255
|
|
108
|
+
})
|
|
109
|
+
// jsqr is CommonJS, so under NodeNext its function is the module's `default` property.
|
|
110
|
+
const result = jsQR.default(pixels, width, width)
|
|
111
|
+
if (!result) throw new Error("jsQR could not read the QR Code")
|
|
112
|
+
return new TextDecoder().decode(new Uint8Array(result.binaryData))
|
|
113
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { SessionTitleFallback } from "../src/session-title-fallback.js"
|
|
3
|
+
|
|
4
|
+
const root = { title: undefined, time: { created: 0 } }
|
|
5
|
+
const child = { ...root, parentID: "ses_parent" }
|
|
6
|
+
|
|
7
|
+
describe("SessionTitleFallback", () => {
|
|
8
|
+
test("supplies timestamped compatibility titles", () => {
|
|
9
|
+
expect(SessionTitleFallback.withTimestampedFallback(root)).toBe("New session - 1970-01-01T00:00:00.000Z")
|
|
10
|
+
expect(SessionTitleFallback.withTimestampedFallback(child)).toBe("Child session - 1970-01-01T00:00:00.000Z")
|
|
11
|
+
expect(SessionTitleFallback.withTimestampedFallback({ ...root, title: "Generated title" })).toBe("Generated title")
|
|
12
|
+
expect(SessionTitleFallback.withTimestampedFallback({ ...root, title: "" })).toBe("")
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test("supplies compact display labels", () => {
|
|
16
|
+
expect(SessionTitleFallback.displayLabel(root)).toBe("New session")
|
|
17
|
+
expect(SessionTitleFallback.displayLabel(child)).toBe("Child session")
|
|
18
|
+
expect(SessionTitleFallback.displayLabel({ title: "", parentID: "ses_parent" })).toBe("Child session")
|
|
19
|
+
expect(SessionTitleFallback.displayLabel({ title: "New session - 2026-07-30T18:45:03.662Z" })).toBe("New session")
|
|
20
|
+
expect(SessionTitleFallback.displayLabel({ title: "Child session - 2026-07-30T18:45:03.662Z" })).toBe(
|
|
21
|
+
"Child session",
|
|
22
|
+
)
|
|
23
|
+
expect(SessionTitleFallback.displayLabel({ title: "Generated title" })).toBe("Generated title")
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test("recognizes historical fallback titles", () => {
|
|
27
|
+
expect(SessionTitleFallback.isFallbackTitle(undefined)).toBeTrue()
|
|
28
|
+
expect(SessionTitleFallback.isFallbackTitle("New session - 2026-07-30T18:45:03.662Z")).toBeTrue()
|
|
29
|
+
expect(SessionTitleFallback.isFallbackTitle("Child session - 2026-07-30T18:45:03.662Z")).toBeTrue()
|
|
30
|
+
expect(SessionTitleFallback.isFallbackTitle("")).toBeFalse()
|
|
31
|
+
expect(SessionTitleFallback.isFallbackTitle("New session - custom")).toBeFalse()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test("recognizes only the fallback associated with a session", () => {
|
|
35
|
+
expect(SessionTitleFallback.isExactRootFallback(root)).toBeTrue()
|
|
36
|
+
expect(
|
|
37
|
+
SessionTitleFallback.isExactRootFallback({ ...root, title: "New session - 1970-01-01T00:00:00.000Z" }),
|
|
38
|
+
).toBeTrue()
|
|
39
|
+
expect(
|
|
40
|
+
SessionTitleFallback.isExactRootFallback({ ...root, title: "New session - 2099-01-01T00:00:00.000Z" }),
|
|
41
|
+
).toBeFalse()
|
|
42
|
+
expect(
|
|
43
|
+
SessionTitleFallback.isExactRootFallback({
|
|
44
|
+
...child,
|
|
45
|
+
title: "Child session - 1970-01-01T00:00:00.000Z",
|
|
46
|
+
}),
|
|
47
|
+
).toBeFalse()
|
|
48
|
+
})
|
|
49
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"extends": "./tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"rootDir": "src",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"noEmit": false,
|
|
8
|
+
"declaration": true
|
|
9
|
+
},
|
|
10
|
+
"include": ["src"],
|
|
11
|
+
"exclude": ["src/**/*.test.ts"]
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"paths": {
|
|
5
|
+
"@zyro-sec/util/effect/layer-node": ["./dist/effect/layer-node.d.ts"],
|
|
6
|
+
"@zyro-sec/util/effect/app-node": ["./dist/effect/app-node.d.ts"]
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"include": ["../core/test/effect/layer-node/layer-node-types.test.ts"]
|
|
10
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"extends": "@tsconfig/bun/tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"types": ["bun"],
|
|
6
|
+
"noUnusedLocals": true,
|
|
7
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
8
|
+
"module": "NodeNext",
|
|
9
|
+
"moduleResolution": "NodeNext",
|
|
10
|
+
"allowImportingTsExtensions": false,
|
|
11
|
+
"allowJs": false,
|
|
12
|
+
"noUncheckedIndexedAccess": false
|
|
13
|
+
}
|
|
14
|
+
}
|