Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions packages/opencode/test/command/altimate-commands.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { describe, test, expect } from "bun:test"
import { Command } from "../../src/command/index"
import { Instance } from "../../src/project/instance"
import { tmpdir } from "../fixture/fixture"

async function withInstance(fn: () => Promise<void>) {
await using tmp = await tmpdir({ git: true })
await Instance.provide({ directory: tmp.path, fn })
}

describe("Altimate builtin commands", () => {
test("all altimate-specific commands are registered", async () => {
await withInstance(async () => {
const commands = await Command.list()
const names = commands.map((c) => c.name)
// These are the altimate_change commands that must ship with the package.
// Regression guard: commit 528af75 fixed discover-and-add-mcps not shipping.
expect(names).toContain("configure-claude")
expect(names).toContain("configure-codex")
expect(names).toContain("discover-and-add-mcps")
expect(names).toContain("feedback")
})
})

test("Command.Default includes all altimate constants", () => {
expect(Command.Default.CONFIGURE_CLAUDE).toBe("configure-claude")
expect(Command.Default.CONFIGURE_CODEX).toBe("configure-codex")
expect(Command.Default.DISCOVER_MCPS).toBe("discover-and-add-mcps")
expect(Command.Default.FEEDBACK).toBe("feedback")
})

test("discover-and-add-mcps has correct metadata and template", async () => {
await withInstance(async () => {
const cmd = await Command.get("discover-and-add-mcps")
expect(cmd).toBeDefined()
expect(cmd.name).toBe("discover-and-add-mcps")
expect(cmd.source).toBe("command")
expect(cmd.description).toBe("discover MCP servers from external AI tool configs and add them")
const template = await cmd.template
expect(template).toContain("mcp_discover")
expect(cmd.hints).toContain("$ARGUMENTS")
})
})
Comment on lines +32 to +43
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check how the template property is defined in Command
ast-grep --pattern $'template: $_'

# Also check the Command interface/type definition
rg -n -A5 'interface.*Command|type.*Command.*=' --type=ts | head -50

Repository: AltimateAI/altimate-code

Length of output: 3377


🏁 Script executed:

#!/bin/bash
# Get the full Command schema definition from config.ts
rg -n -B5 -A20 'export const Command = z' packages/opencode/src/config/config.ts

# Also check if there's a Command class with template getter
rg -n -A15 'class Command|interface Command' packages/opencode/src --type=ts

Repository: AltimateAI/altimate-code

Length of output: 931


🏁 Script executed:

#!/bin/bash
# Find Command.get() implementation
rg -n -A15 'static.*get.*discover-and-add-mcps|\.get\s*\(\s*name' packages/opencode/src --type=ts | head -60

# Search for Command class with get method
rg -n 'class Command|export.*Command.*get' packages/opencode/src --type=ts -B2 -A10 | head -80

Repository: AltimateAI/altimate-code

Length of output: 4271


🏁 Script executed:

#!/bin/bash
# Search for Command class in opencode package
fd -t f "\.ts$" packages/opencode/src | xargs grep -l "class Command" | head -10

# Search for exports that look like Command.get
rg -n "export.*Command.*|Command\.get" packages/opencode/src --type=ts | grep -v "CommandInput\|CommandOption\|CommandData" | head -40

Repository: AltimateAI/altimate-code

Length of output: 3471


🏁 Script executed:

#!/bin/bash
# Look for Command class in prompt.ts and nearby files
rg -n "class Command\|namespace Command" packages/opencode/src/session/prompt.ts -B5 -A20

# Also search in the same directory
rg -n "class Command" packages/opencode/src/session --type=ts -B2 -A15

Repository: AltimateAI/altimate-code

Length of output: 50


🏁 Script executed:

#!/bin/bash
# Check imports and context around the Command.get() call in prompt.ts
sed -n '1,50p' packages/opencode/src/session/prompt.ts | head -30

# Check around line 1885
sed -n '1870,1895p' packages/opencode/src/session/prompt.ts

Repository: AltimateAI/altimate-code

Length of output: 2506


🏁 Script executed:

#!/bin/bash
# Search for Command namespace/export in prompt.ts
rg -n "export.*Command\|namespace Command" packages/opencode/src/session/prompt.ts -B2 -A30 | head -100

Repository: AltimateAI/altimate-code

Length of output: 50


🏁 Script executed:

#!/bin/bash
# Search for Command definition in prompt.ts more broadly
rg -n "Command" packages/opencode/src/session/prompt.ts | head -30

# Also get the file size to understand scope
wc -l packages/opencode/src/session/prompt.ts

Repository: AltimateAI/altimate-code

Length of output: 850


🏁 Script executed:

#!/bin/bash
# Find the command module
fd -type f "command.*\.ts" packages/opencode/src | grep -E "^packages/opencode/src/command"

# Also check if it's a directory with index
ls -la packages/opencode/src/command/ 2>/dev/null || echo "Not a directory"

Repository: AltimateAI/altimate-code

Length of output: 486


🏁 Script executed:

#!/bin/bash
# Read the command index file
cat -n packages/opencode/src/command/index.ts | head -200

Repository: AltimateAI/altimate-code

Length of output: 8339


The await on cmd.template is unnecessary for the default "discover-and-add-mcps" command.

The template property is defined as Promise<string> | string (in packages/opencode/src/command/index.ts:51). Default commands like "discover-and-add-mcps" use a getter that returns a plain string directly (line 139-140), so awaiting it is harmless but redundant. This works because awaiting a non-Promise value simply returns that value. Consider removing the await on line 39 if the intent is to test only default commands, or keep it if you want to support both synchronous and asynchronous command sources (MCP commands return promises).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/command/altimate-commands.test.ts` around lines 32 -
43, The test unnecessarily awaits cmd.template even though default commands like
"discover-and-add-mcps" return a plain string; update the test in
altimate-commands.test.ts to stop awaiting cmd.template (e.g., use const
template = cmd.template) so it asserts the synchronous template directly, or
alternatively normalize both sync/async by using Promise.resolve(cmd.template)
before assertions; refer to Command.get and the cmd.template property to locate
the change.


test("configure-claude has correct metadata", async () => {
await withInstance(async () => {
const cmd = await Command.get("configure-claude")
expect(cmd).toBeDefined()
expect(cmd.name).toBe("configure-claude")
expect(cmd.source).toBe("command")
expect(cmd.description).toBe("configure /altimate command in Claude Code")
})
})

test("configure-codex has correct metadata", async () => {
await withInstance(async () => {
const cmd = await Command.get("configure-codex")
expect(cmd).toBeDefined()
expect(cmd.name).toBe("configure-codex")
expect(cmd.source).toBe("command")
expect(cmd.description).toBe("configure altimate skill in Codex CLI")
})
})
})
32 changes: 32 additions & 0 deletions packages/opencode/test/command/hints.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, test, expect } from "bun:test"
import { Command } from "../../src/command/index"

describe("Command.hints — template placeholder extraction", () => {
test("extracts numbered placeholders in order", () => {
expect(Command.hints("Do $1 then $2")).toEqual(["$1", "$2"])
})

test("deduplicates repeated numbered placeholders", () => {
expect(Command.hints("Use $1 and $1 again")).toEqual(["$1"])
})

test("extracts $ARGUMENTS", () => {
expect(Command.hints("Run with $ARGUMENTS")).toEqual(["$ARGUMENTS"])
})

test("numbered placeholders before $ARGUMENTS", () => {
expect(Command.hints("Do $2 then $1 with $ARGUMENTS")).toEqual(["$1", "$2", "$ARGUMENTS"])
})

test("returns empty for no placeholders", () => {
expect(Command.hints("Plain text with no variables")).toEqual([])
})

test("handles template with only $ARGUMENTS", () => {
expect(Command.hints("If $ARGUMENTS contains --scope global")).toEqual(["$ARGUMENTS"])
})

test("only recognises $N and $ARGUMENTS — not $OTHER or $FOO", () => {
expect(Command.hints("Use $OTHER and $FOO")).toEqual([])
})
})
Loading