-
Notifications
You must be signed in to change notification settings - Fork 134
feat(tui): install skills via typed query in the /skills list #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sahrizvi
wants to merge
3
commits into
main
Choose a base branch
from
fix/skills-install-from-typed-url
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+279
−23
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
packages/opencode/test/altimate/skill-install-classifier.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { describe, expect, test } from "bun:test" | ||
| import { classifyInstallSource, normalizeInstallSource } from "@/plugin/tui/altimate/skill-ops" | ||
|
|
||
| // classifyInstallSource is the shared classifier for the DialogSkillList's "Install <query>" | ||
| // affordance and installSkillDirect. Keeping the two in lockstep matters: an earlier version | ||
| // of the list used `q.includes("/") && q.length >= 3`, which offered the Install option for | ||
| // three-segment paths and other shapes the installer then rejected as "Path not found". | ||
| // A clean two-segment `owner/repo` is intentionally accepted as GitHub shorthand — skill | ||
| // names can't contain a slash so no search result is hijacked. These tests pin the | ||
| // classifier's edge cases so the UI's install-preview and the installer can't drift. | ||
| describe("classifyInstallSource", () => { | ||
| test("recognises github owner/repo shorthand", () => { | ||
| expect(classifyInstallSource("anthropics/skills")).toBe("owner-repo") | ||
| expect(classifyInstallSource("owner/repo.git")).toBe("owner-repo") | ||
| expect(classifyInstallSource("Owner_1/repo-2.name")).toBe("owner-repo") | ||
| }) | ||
|
|
||
| test("recognises http(s) URLs", () => { | ||
| expect(classifyInstallSource("https://github.com/anthropics/skills.git")).toBe("github-url") | ||
| expect(classifyInstallSource("http://example.com/thing")).toBe("github-url") | ||
| }) | ||
|
|
||
| test("recognises POSIX absolute paths", () => { | ||
| expect(classifyInstallSource("/tmp/my-skill")).toBe("absolute-path") | ||
| expect(classifyInstallSource("/home/user/skills/foo")).toBe("absolute-path") | ||
| }) | ||
|
|
||
| test("recognises Windows drive-letter paths", () => { | ||
| expect(classifyInstallSource("C:\\Users\\me\\skills")).toBe("absolute-path") | ||
| expect(classifyInstallSource("D:/skills/foo")).toBe("absolute-path") | ||
| }) | ||
|
|
||
| test("rejects short strings that the installer would refuse", () => { | ||
| expect(classifyInstallSource("a")).toBeNull() | ||
| expect(classifyInstallSource("ab")).toBeNull() | ||
| expect(classifyInstallSource("")).toBeNull() | ||
| }) | ||
|
|
||
| test("rejects three-segment paths (sub-paths inside a repo)", () => { | ||
| // Historically `q.includes("/")` misfired on these — the list surfaced an Install | ||
| // option that installSkillDirect then refused with "Path not found". | ||
| expect(classifyInstallSource("owner/repo/subpath")).toBeNull() | ||
| expect(classifyInstallSource("dbt/snowflake/thing")).toBeNull() | ||
| }) | ||
|
|
||
| test("clean two-segment strings are treated as owner/repo shorthand", () => { | ||
| // Intentional feature, not a bug: skill names can't contain a slash (see the | ||
| // `^[a-z][a-z0-9]*(-[a-z0-9]+)*$` grammar enforced by createSkillDirect), so any | ||
| // two-segment string typed into the filter cannot collide with a real skill name | ||
| // and is unambiguously a GitHub `owner/repo` shorthand. | ||
| expect(classifyInstallSource("dbt/snowflake")).toBe("owner-repo") | ||
| expect(classifyInstallSource("anthropics/skills")).toBe("owner-repo") | ||
| }) | ||
|
|
||
| test("owners whose name starts with `http` still classify as owner-repo, not URL", () => { | ||
| // Regression pin for a real bug where installSkillDirect used | ||
| // `cleaned.startsWith("http")` to route between "already a URL" and "build a | ||
| // github.com URL": that misrouted owner names literally beginning with `http` | ||
| // (e.g. `httpie/httpie`, `http-party/http-server`) as pre-formed URLs, then failed | ||
| // to clone. The fix branches on the classifier's `kind` instead of a prefix probe; | ||
| // this test locks in the classifier's side of the contract. | ||
| expect(classifyInstallSource("httpie/httpie")).toBe("owner-repo") | ||
| expect(classifyInstallSource("http-party/http-server")).toBe("owner-repo") | ||
| expect(classifyInstallSource("httpwg/http-extensions")).toBe("owner-repo") | ||
| }) | ||
|
|
||
| test("rejects `~`-prefixed and relative paths — ambiguous with skill names", () => { | ||
| expect(classifyInstallSource("~/skills/foo")).toBeNull() | ||
| expect(classifyInstallSource("./local")).toBeNull() | ||
| expect(classifyInstallSource("../thing")).toBeNull() | ||
| }) | ||
|
|
||
| test("rejects bare identifiers with no slash and no path prefix", () => { | ||
| expect(classifyInstallSource("skill-name")).toBeNull() | ||
| expect(classifyInstallSource("dbt-snowflake")).toBeNull() | ||
| }) | ||
|
|
||
| test("strips trailing dots and `.git` before classifying", () => { | ||
| expect(classifyInstallSource("owner/repo.git")).toBe("owner-repo") | ||
| expect(classifyInstallSource("https://github.com/x/y.git")).toBe("github-url") | ||
| expect(classifyInstallSource("owner/repo.")).toBe("owner-repo") | ||
| }) | ||
|
|
||
| test("trims surrounding whitespace before classifying", () => { | ||
| expect(classifyInstallSource(" owner/repo ")).toBe("owner-repo") | ||
| expect(classifyInstallSource("\thttps://github.com/x/y\n")).toBe("github-url") | ||
| }) | ||
| }) | ||
|
|
||
| // normalizeInstallSource is the shared trim/strip helper that installSkillDirect uses | ||
| // before building a clone URL from an `owner/repo` shorthand. Without it, an input like | ||
| // `owner/repo.git` (accepted by the classifier because it strips `.git`) would produce | ||
| // `https://github.com/owner/repo.git.git` — real bug flagged in review. | ||
| describe("normalizeInstallSource", () => { | ||
| test("strips a trailing `.git` suffix", () => { | ||
| expect(normalizeInstallSource("owner/repo.git")).toBe("owner/repo") | ||
| expect(normalizeInstallSource("https://github.com/x/y.git")).toBe("https://github.com/x/y") | ||
| }) | ||
|
|
||
| test("strips trailing dots", () => { | ||
| expect(normalizeInstallSource("owner/repo.")).toBe("owner/repo") | ||
| expect(normalizeInstallSource("owner/repo...")).toBe("owner/repo") | ||
| }) | ||
|
|
||
| test("trims surrounding whitespace", () => { | ||
| expect(normalizeInstallSource(" owner/repo ")).toBe("owner/repo") | ||
| expect(normalizeInstallSource("\n\towner/repo\r\n")).toBe("owner/repo") | ||
| }) | ||
|
|
||
| test("returns the source unchanged when nothing to strip", () => { | ||
| expect(normalizeInstallSource("owner/repo")).toBe("owner/repo") | ||
| expect(normalizeInstallSource("/tmp/skills")).toBe("/tmp/skills") | ||
| expect(normalizeInstallSource("")).toBe("") | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[🟠 MEDIUM] Bug: Inconsistent string normalization
The
classifyInstallSourcefunction accepts leading/trailing whitespaces and strips.gitsuffixes (e.g.," owner/repo "), returning a validkind. However,installSkillDirectrelies on the unmodifiednormalizedstring.If
normalizedhas spaces or an existing.gitsuffix (e.g.," owner/repo "or"owner/repo.git"), it passes theifcheck but generates a malformed URL likehttps://github.com/ owner/repo .gitorhttps://github.com/owner/repo.git.git.Suggestion:
Ensure the string used to construct the URL matches the cleaned format recognized by the classifier.