@ftrdotdev/pi-tracker 0.7.0 → 0.9.0
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/CHANGELOG.md +369 -0
- package/README.md +88 -9
- package/package.json +27 -16
- package/src/compaction/candidate.test.ts +66 -125
- package/src/compaction/classifier.test.ts +22 -2
- package/src/compaction/classifier.ts +35 -22
- package/src/compaction/completion.test.ts +24 -16
- package/src/compaction/completion.ts +1 -1
- package/src/compaction/decision-record.test.ts +1 -1
- package/src/compaction/decision-record.ts +1 -1
- package/src/compaction/digest.test.ts +34 -34
- package/src/compaction/footprint.ts +2 -4
- package/src/compaction/settings.test.ts +5 -1
- package/src/compaction/settings.ts +1 -1
- package/src/compaction/settle.test.ts +50 -10
- package/src/compaction/settle.ts +5 -5
- package/src/core/deps.test.ts +128 -109
- package/src/core/deps.ts +3 -2
- package/src/core/domain.test.ts +99 -68
- package/src/core/domain.ts +16 -10
- package/src/core/persistence.test.ts +18 -19
- package/src/core/persistence.ts +4 -3
- package/src/core/store.test.ts +129 -167
- package/src/core/store.ts +77 -57
- package/src/harness-collection.test.ts +75 -0
- package/src/index.test.ts +59 -17
- package/src/index.ts +63 -64
- package/src/layers.test.ts +101 -0
- package/src/layers.ts +46 -0
- package/src/presentation/tool-metadata.test.ts +36 -38
- package/src/presentation/tool-metadata.ts +127 -130
- package/src/presentation/ui.test.ts +128 -67
- package/src/presentation/ui.ts +68 -20
- package/src/presentation/vim-settings.test.ts +101 -0
- package/src/presentation/vim-settings.ts +59 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Each test is its own entry point: it builds a fresh layer for one scenario and
|
|
2
|
+
// runs its effects inside it, so providing there is the pattern the rule allows.
|
|
3
|
+
/* oxlint-disable effecttsgo/strict-effect-provide */
|
|
4
|
+
import { assert, it } from "@effect/vitest";
|
|
5
|
+
import { Effect, PlatformError } from "effect";
|
|
6
|
+
import * as FileSystem from "effect/FileSystem";
|
|
7
|
+
import { readVimEnabled, VimSettingsService } from "./vim-settings.ts";
|
|
8
|
+
|
|
9
|
+
const TEST_PATH = "/tmp/tracker-vim-test/tui.json";
|
|
10
|
+
|
|
11
|
+
interface MemFs {
|
|
12
|
+
readonly fs: Partial<FileSystem.FileSystem>;
|
|
13
|
+
readonly files: Map<string, string>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function makeMemFs(init: Record<string, string> = {}): MemFs {
|
|
17
|
+
const files = new Map<string, string>(Object.entries(init));
|
|
18
|
+
const fs: Partial<FileSystem.FileSystem> = {
|
|
19
|
+
readFileString: (path) =>
|
|
20
|
+
files.has(path)
|
|
21
|
+
? Effect.succeed(files.get(path)!)
|
|
22
|
+
: Effect.fail(
|
|
23
|
+
PlatformError.systemError({
|
|
24
|
+
_tag: "NotFound",
|
|
25
|
+
module: "FileSystem",
|
|
26
|
+
method: "readFileString",
|
|
27
|
+
pathOrDescriptor: path,
|
|
28
|
+
description: "No such file",
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
};
|
|
32
|
+
return { fs, files };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const load = (): Effect.Effect<boolean, never, VimSettingsService> =>
|
|
36
|
+
Effect.gen(function* () {
|
|
37
|
+
const service = yield* VimSettingsService;
|
|
38
|
+
return yield* service.load;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const runWithMem = (
|
|
42
|
+
mem: MemFs,
|
|
43
|
+
program: Effect.Effect<boolean, never, VimSettingsService>,
|
|
44
|
+
): Effect.Effect<boolean, never> =>
|
|
45
|
+
program.pipe(Effect.provide(VimSettingsService.layerTest(TEST_PATH, mem.fs)));
|
|
46
|
+
|
|
47
|
+
it.effect("load returns off when the file is missing", () =>
|
|
48
|
+
Effect.gen(function* () {
|
|
49
|
+
const enabled = yield* runWithMem(makeMemFs(), load());
|
|
50
|
+
assert.strictEqual(enabled, false);
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
it.effect("load returns on when the file stores vim true", () =>
|
|
55
|
+
Effect.gen(function* () {
|
|
56
|
+
const mem = makeMemFs({ [TEST_PATH]: JSON.stringify({ vim: true }) });
|
|
57
|
+
const enabled = yield* runWithMem(mem, load());
|
|
58
|
+
assert.strictEqual(enabled, true);
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
it.effect("load returns off when the file stores vim false", () =>
|
|
63
|
+
Effect.gen(function* () {
|
|
64
|
+
const mem = makeMemFs({ [TEST_PATH]: JSON.stringify({ vim: false }) });
|
|
65
|
+
const enabled = yield* runWithMem(mem, load());
|
|
66
|
+
assert.strictEqual(enabled, false);
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
it.effect("load returns off when vim is not a boolean", () =>
|
|
71
|
+
Effect.gen(function* () {
|
|
72
|
+
const mem = makeMemFs({ [TEST_PATH]: JSON.stringify({ vim: "yes" }) });
|
|
73
|
+
const enabled = yield* runWithMem(mem, load());
|
|
74
|
+
assert.strictEqual(enabled, false);
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
it.effect("load returns off when the file is not valid JSON", () =>
|
|
79
|
+
Effect.gen(function* () {
|
|
80
|
+
const mem = makeMemFs({ [TEST_PATH]: "not json{" });
|
|
81
|
+
const enabled = yield* runWithMem(mem, load());
|
|
82
|
+
assert.strictEqual(enabled, false);
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
it.effect("load returns off when the file is not an object", () =>
|
|
87
|
+
Effect.gen(function* () {
|
|
88
|
+
const mem = makeMemFs({ [TEST_PATH]: JSON.stringify([true]) });
|
|
89
|
+
const enabled = yield* runWithMem(mem, load());
|
|
90
|
+
assert.strictEqual(enabled, false);
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
it("readVimEnabled reads only a boolean vim key", () => {
|
|
95
|
+
assert.strictEqual(readVimEnabled({ vim: true }), true);
|
|
96
|
+
assert.strictEqual(readVimEnabled({ vim: false }), false);
|
|
97
|
+
assert.strictEqual(readVimEnabled({ vim: 1 }), false);
|
|
98
|
+
assert.strictEqual(readVimEnabled({}), false);
|
|
99
|
+
assert.strictEqual(readVimEnabled(null), false);
|
|
100
|
+
assert.strictEqual(readVimEnabled("vim"), false);
|
|
101
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Option, Predicate, Schema } from "effect";
|
|
2
|
+
import * as FileSystem from "effect/FileSystem";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The tracker's reader of the shared TUI settings file's `vim` toggle. The
|
|
6
|
+
* toggle gates h/j/k/l navigation in the `/tracker` overlay. It fails closed:
|
|
7
|
+
* a missing, unreadable, or malformed value reads as off, so the overlay keeps
|
|
8
|
+
* its arrow-only behavior.
|
|
9
|
+
*
|
|
10
|
+
* The file is owned by `packages/tui/src/config.ts`; the tracker only reads the
|
|
11
|
+
* one key. The caller passes the path, so the tracker never re-declares the
|
|
12
|
+
* file name.
|
|
13
|
+
*/
|
|
14
|
+
export const VIM_KEY = "vim";
|
|
15
|
+
|
|
16
|
+
const FileSchema = Schema.fromJsonString(Schema.Unknown);
|
|
17
|
+
const BooleanSchema = Schema.Boolean;
|
|
18
|
+
|
|
19
|
+
/** The `vim` boolean, or `false` when the value is absent or not a boolean. */
|
|
20
|
+
export const readVimEnabled = (parsed: unknown): boolean => {
|
|
21
|
+
if (!Predicate.isObject(parsed)) return false;
|
|
22
|
+
const raw = Predicate.hasProperty(VIM_KEY)(parsed) ? parsed[VIM_KEY] : undefined;
|
|
23
|
+
return Option.getOrElse(Schema.decodeUnknownOption(BooleanSchema)(raw), () => false);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export class VimSettingsService extends Context.Service<
|
|
27
|
+
VimSettingsService,
|
|
28
|
+
{
|
|
29
|
+
readonly path: string;
|
|
30
|
+
/** Never fails: every read, parse, or shape problem yields `false` (off). */
|
|
31
|
+
readonly load: Effect.Effect<boolean>;
|
|
32
|
+
}
|
|
33
|
+
>()("@ftrdotdev/pi-tracker/presentation/vim-settings/VimSettingsService") {
|
|
34
|
+
static make(path: string): Layer.Layer<VimSettingsService, never, FileSystem.FileSystem> {
|
|
35
|
+
return Layer.effect(
|
|
36
|
+
VimSettingsService,
|
|
37
|
+
Effect.gen(function* () {
|
|
38
|
+
const fs = yield* FileSystem.FileSystem;
|
|
39
|
+
const load = Effect.gen(function* () {
|
|
40
|
+
const raw = yield* fs.readFileString(path);
|
|
41
|
+
// `Schema.Unknown` accepts any JSON value; `readVimEnabled` narrows it.
|
|
42
|
+
const parsed = yield* Schema.decodeEffect(FileSchema)(raw);
|
|
43
|
+
return readVimEnabled(parsed);
|
|
44
|
+
}).pipe(
|
|
45
|
+
Effect.catchCause(() =>
|
|
46
|
+
Effect.logWarning("tracker: vim setting unreadable, using off").pipe(Effect.as(false)),
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
return VimSettingsService.of({ path, load });
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static readonly layerTest = (
|
|
55
|
+
path: string,
|
|
56
|
+
fileSystem: Partial<FileSystem.FileSystem>,
|
|
57
|
+
): Layer.Layer<VimSettingsService> =>
|
|
58
|
+
VimSettingsService.make(path).pipe(Layer.provide(FileSystem.layerNoop(fileSystem)));
|
|
59
|
+
}
|