|
1 | | -import { describe, expect } from "bun:test" |
| 1 | +import { describe, expect, test } from "bun:test" |
2 | 2 | import { Effect, Layer } from "effect" |
3 | | -import { Skill } from "../../src/skill" |
| 3 | +import { Skill, snapshotProjectOf } from "../../src/skill" |
4 | 4 | import { Discovery } from "../../src/skill/discovery" |
5 | 5 | import { RuntimeFlags } from "../../src/effect/runtime-flags" |
6 | 6 | import { EventV2Bridge } from "../../src/event-v2-bridge" |
@@ -108,6 +108,27 @@ const withHome = <A, E, R>(home: string, self: Effect.Effect<A, E, R>) => |
108 | 108 | }), |
109 | 109 | ) |
110 | 110 |
|
| 111 | +describe("workspace snapshot attribution", () => { |
| 112 | + // `at > 0` skipped index 0, so a project opened AT the filesystem root — its |
| 113 | + // snapshot living at `/.altimate-code/skill/_workspace/` — was read as "no |
| 114 | + // managed project" and served without consulting its manifest. (review) |
| 115 | + test("a project at the filesystem root is a project, not an absence of one", () => { |
| 116 | + expect(snapshotProjectOf(path.join(path.sep, ".altimate-code", "skill", "_workspace", "p", "SKILL.md"))).toBe( |
| 117 | + path.sep, |
| 118 | + ) |
| 119 | + }) |
| 120 | + |
| 121 | + test("an ordinary skill belongs to no snapshot", () => { |
| 122 | + expect(snapshotProjectOf(path.join(path.sep, "proj", ".opencode", "skill", "s", "SKILL.md"))).toBeNull() |
| 123 | + }) |
| 124 | + |
| 125 | + test("a nested project keeps its own root", () => { |
| 126 | + expect( |
| 127 | + snapshotProjectOf(path.join(path.sep, "a", "b", ".altimate-code", "skill", "_workspace", "p", "SKILL.md")), |
| 128 | + ).toBe(path.join(path.sep, "a", "b")) |
| 129 | + }) |
| 130 | +}) |
| 131 | + |
111 | 132 | describe("skill", () => { |
112 | 133 | it.live("discovers skills from .opencode/skill/ directory", () => |
113 | 134 | provideTmpdirInstance( |
@@ -734,6 +755,60 @@ description: A skill in the .opencode/skills directory. |
734 | 755 | ), |
735 | 756 | ) |
736 | 757 |
|
| 758 | + // `scan` follows symlinks, so a link from any other scanned skill directory |
| 759 | + // into `_workspace` produces a match whose own path carries no managed |
| 760 | + // component. Attributing on the matched string rather than the real one read |
| 761 | + // the snapshot straight past the gate. (review) |
| 762 | + it.live("a symlink into another account's snapshot is not a way in", () => |
| 763 | + provideTmpdirInstance( |
| 764 | + (dir) => |
| 765 | + withHome( |
| 766 | + dir, |
| 767 | + Effect.gen(function* () { |
| 768 | + yield* Effect.promise(() => writeSnapshot(dir, credentialDigest(API_URL, TENANT, "someone-else"))) |
| 769 | + yield* Effect.promise(async () => { |
| 770 | + await fs.mkdir(path.join(dir, ".opencode", "skill"), { recursive: true }) |
| 771 | + await fs.symlink( |
| 772 | + path.join(dir, MANAGED, "pub-abc123"), |
| 773 | + path.join(dir, ".opencode", "skill", "alias"), |
| 774 | + "dir", |
| 775 | + ) |
| 776 | + }) |
| 777 | + |
| 778 | + const skill = yield* Skill.Service |
| 779 | + expect((yield* skill.all()).find((s) => s.name === "workspace-synced")).toBeUndefined() |
| 780 | + }), |
| 781 | + ), |
| 782 | + { git: true }, |
| 783 | + ), |
| 784 | + ) |
| 785 | + |
| 786 | + // The same link, but to a snapshot that IS ours: the gate withholds what is |
| 787 | + // foreign, not everything it cannot recognise at a glance. |
| 788 | + it.live("a symlink into our own snapshot still resolves to a usable skill", () => |
| 789 | + provideTmpdirInstance( |
| 790 | + (dir) => |
| 791 | + withHome( |
| 792 | + dir, |
| 793 | + Effect.gen(function* () { |
| 794 | + yield* Effect.promise(() => writeSnapshot(dir, FIXTURE_ACCOUNT)) |
| 795 | + yield* Effect.promise(async () => { |
| 796 | + await fs.mkdir(path.join(dir, ".opencode", "skill"), { recursive: true }) |
| 797 | + await fs.symlink( |
| 798 | + path.join(dir, MANAGED, "pub-abc123"), |
| 799 | + path.join(dir, ".opencode", "skill", "alias"), |
| 800 | + "dir", |
| 801 | + ) |
| 802 | + }) |
| 803 | + |
| 804 | + const skill = yield* Skill.Service |
| 805 | + expect((yield* skill.all()).find((s) => s.name === "workspace-synced")).toBeDefined() |
| 806 | + }), |
| 807 | + ), |
| 808 | + { git: true }, |
| 809 | + ), |
| 810 | + ) |
| 811 | + |
737 | 812 | // A snapshot from before the manifest carried an account cannot be |
738 | 813 | // attributed to anyone, so it is withheld rather than served to whoever |
739 | 814 | // happens to be logged in. The sync drops and re-fetches it. |
|
0 commit comments