-
Notifications
You must be signed in to change notification settings - Fork 188
Add E2E tests for skills overwrite protection and CLI #4010
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
JAORMX
wants to merge
3
commits into
main
Choose a base branch
from
3655-e2e-skills-tests
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.
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
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,189 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package e2e_test | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/stacklok/toolhive/test/e2e" | ||
| ) | ||
|
|
||
| var _ = Describe("Skills CLI", Label("api", "cli", "skills", "e2e"), func() { | ||
| var ( | ||
| config *e2e.ServerConfig | ||
| apiServer *e2e.Server | ||
| thvConfig *e2e.TestConfig | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| config = e2e.NewServerConfig() | ||
| apiServer = e2e.StartServer(config) | ||
| thvConfig = e2e.NewTestConfig() | ||
| }) | ||
|
|
||
| // thvSkillCmd creates a THVCommand for `thv skill <args>` with | ||
| // TOOLHIVE_API_URL pointing to the test server. | ||
| thvSkillCmd := func(args ...string) *e2e.THVCommand { | ||
| fullArgs := append([]string{"skill"}, args...) | ||
| return e2e.NewTHVCommand(thvConfig, fullArgs...). | ||
| WithEnv("TOOLHIVE_API_URL=" + apiServer.BaseURL()) | ||
| } | ||
|
|
||
| Describe("thv skill validate", func() { | ||
| It("should succeed for a valid skill directory", func() { | ||
| skillDir := createTestSkillDir("cli-valid-skill", "A valid skill for CLI testing") | ||
|
|
||
| stdout, _ := thvSkillCmd("validate", skillDir).ExpectSuccess() | ||
| // Text output should not contain "Error:" lines for a valid skill | ||
| Expect(stdout).ToNot(ContainSubstring("Error:")) | ||
| }) | ||
|
|
||
| It("should succeed with JSON output", func() { | ||
| skillDir := createTestSkillDir("cli-valid-json", "A valid skill for JSON output") | ||
|
|
||
| stdout, _ := thvSkillCmd("validate", "--format", "json", skillDir).ExpectSuccess() | ||
|
|
||
| var result validationResultResponse | ||
| Expect(json.Unmarshal([]byte(stdout), &result)).To(Succeed()) | ||
| Expect(result.Valid).To(BeTrue()) | ||
| }) | ||
|
|
||
| It("should fail for an invalid skill directory", func() { | ||
| emptyDir := GinkgoT().TempDir() | ||
|
|
||
| _, _, err := thvSkillCmd("validate", emptyDir).Run() | ||
| Expect(err).To(HaveOccurred(), "validate should fail for directory without SKILL.md") | ||
| }) | ||
| }) | ||
|
|
||
| Describe("thv skill build", func() { | ||
| It("should build a valid skill and print the reference", func() { | ||
| skillDir := createTestSkillDir("cli-build-skill", "A skill for CLI build testing") | ||
|
|
||
| stdout, _ := thvSkillCmd("build", skillDir).ExpectSuccess() | ||
| // The build command should output something (the reference) | ||
| Expect(strings.TrimSpace(stdout)).ToNot(BeEmpty()) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("thv skill install and list", func() { | ||
| It("should install a skill and list it", func() { | ||
| skillName := fmt.Sprintf("cli-install-%d", GinkgoRandomSeed()) | ||
|
|
||
| By("Installing the skill") | ||
| thvSkillCmd("install", skillName).ExpectSuccess() | ||
|
|
||
| By("Listing skills in text format — should show the installed skill") | ||
| stdout, _ := thvSkillCmd("list").ExpectSuccess() | ||
| Expect(stdout).To(ContainSubstring(skillName)) | ||
|
|
||
| By("Listing skills in JSON format") | ||
| jsonOut, _ := thvSkillCmd("list", "--format", "json").ExpectSuccess() | ||
| var skills []json.RawMessage | ||
| Expect(json.Unmarshal([]byte(jsonOut), &skills)).To(Succeed()) | ||
| Expect(skills).ToNot(BeEmpty()) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("thv skill info", func() { | ||
| It("should show info for an installed skill", func() { | ||
| skillName := fmt.Sprintf("cli-info-%d", GinkgoRandomSeed()) | ||
|
|
||
| By("Installing the skill") | ||
| thvSkillCmd("install", skillName).ExpectSuccess() | ||
|
|
||
| By("Getting info in text format") | ||
| stdout, _ := thvSkillCmd("info", skillName).ExpectSuccess() | ||
| Expect(stdout).To(ContainSubstring(skillName)) | ||
|
|
||
| By("Getting info in JSON format") | ||
| jsonOut, _ := thvSkillCmd("info", "--format", "json", skillName).ExpectSuccess() | ||
| Expect(jsonOut).To(ContainSubstring(skillName)) | ||
| }) | ||
|
|
||
| It("should fail for a non-existent skill", func() { | ||
| _, _, err := thvSkillCmd("info", "no-such-skill-xyz").Run() | ||
| Expect(err).To(HaveOccurred()) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("thv skill uninstall", func() { | ||
| It("should uninstall an installed skill", func() { | ||
| skillName := fmt.Sprintf("cli-uninstall-%d", GinkgoRandomSeed()) | ||
|
|
||
| By("Installing the skill") | ||
| thvSkillCmd("install", skillName).ExpectSuccess() | ||
|
|
||
| By("Uninstalling the skill") | ||
| thvSkillCmd("uninstall", skillName).ExpectSuccess() | ||
|
|
||
| By("Verifying the skill is no longer listed") | ||
| stdout, _ := thvSkillCmd("list").ExpectSuccess() | ||
| Expect(stdout).ToNot(ContainSubstring(skillName)) | ||
| }) | ||
|
|
||
| It("should fail for a non-existent skill", func() { | ||
| _, _, err := thvSkillCmd("uninstall", "no-such-skill-xyz").Run() | ||
| Expect(err).To(HaveOccurred()) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("CLI full lifecycle", func() { | ||
| It("should support validate → build → install → list → info → uninstall → list", func() { | ||
| skillName := fmt.Sprintf("cli-lifecycle-%d", GinkgoRandomSeed()) | ||
|
|
||
| By("Creating a valid skill directory") | ||
| parentDir := GinkgoT().TempDir() | ||
| skillDir := filepath.Join(parentDir, skillName) | ||
| Expect(os.MkdirAll(skillDir, 0o755)).To(Succeed()) | ||
|
|
||
| skillMD := fmt.Sprintf(`--- | ||
| name: %s | ||
| description: Full lifecycle CLI test | ||
| version: 1.0.0 | ||
| --- | ||
|
|
||
| # %s | ||
|
|
||
| A test skill for the full CLI lifecycle. | ||
| `, skillName, skillName) | ||
| Expect(os.WriteFile( | ||
| filepath.Join(skillDir, "SKILL.md"), | ||
| []byte(skillMD), | ||
| 0o644, | ||
| )).To(Succeed()) | ||
|
|
||
| By("Validating the skill") | ||
| thvSkillCmd("validate", skillDir).ExpectSuccess() | ||
|
|
||
| By("Building the skill") | ||
| thvSkillCmd("build", skillDir).ExpectSuccess() | ||
|
|
||
| By("Installing the skill by name (pending)") | ||
| thvSkillCmd("install", skillName).ExpectSuccess() | ||
|
|
||
| By("Listing skills — should contain the skill") | ||
| listOut, _ := thvSkillCmd("list").ExpectSuccess() | ||
| Expect(listOut).To(ContainSubstring(skillName)) | ||
|
|
||
| By("Getting skill info") | ||
| infoOut, _ := thvSkillCmd("info", skillName).ExpectSuccess() | ||
| Expect(infoOut).To(ContainSubstring(skillName)) | ||
|
|
||
| By("Uninstalling the skill") | ||
| thvSkillCmd("uninstall", skillName).ExpectSuccess() | ||
|
|
||
| By("Listing skills — should no longer contain the skill") | ||
| listOut2, _ := thvSkillCmd("list").ExpectSuccess() | ||
| Expect(listOut2).ToNot(ContainSubstring(skillName)) | ||
| }) | ||
| }) | ||
| }) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.