Skip to content

ScriptExecutor interface and ScriptLanguage type #7436

Description

@wbreza

ScriptExecutor Interface and ScriptLanguage Type

Part of #7435 — Multi-Language Hook Support

User Story

As a template author, I want azd to understand that my hook script is written in a specific programming language so that it can handle execution appropriately instead of treating everything as a shell script.

Solution Approach

Create pkg/tools/language/executor.go (NEW):

  • Define ScriptLanguage type (string) with constants: ScriptLanguageUnknown (""), ScriptLanguagePython ("python"), ScriptLanguageJavaScript ("js"), ScriptLanguageTypeScript ("ts"), ScriptLanguageDotNet ("dotnet").
  • Define ScriptExecutor interface:
    • Language() ScriptLanguage
    • Prepare(ctx context.Context, scriptPath string) error — runtime check, dependency install, build
    • Execute(ctx context.Context, scriptPath string, options tools.ExecOptions) (exec.RunResult, error)
  • Implement GetExecutor(language ScriptLanguage, ...) (ScriptExecutor, error) factory. Accept dependencies via parameters (not global state) — specifically exec.CommandRunner. Phase 1: Python returns real executor; JS/TS/DotNet return ErrUnsupportedLanguage sentinel.
  • Implement InferLanguageFromPath(path string) ScriptLanguage mapping .py → Python, .js → JS, .ts → TS, .cs → DotNet, unknown → ScriptLanguageUnknown.

Create pkg/tools/language/executor_test.go (NEW):

  • Table-driven tests for InferLanguageFromPath covering all extensions + unknown.
  • Tests for GetExecutor returning real executor for Python, ErrUnsupportedLanguage for others.

Files: pkg/tools/language/executor.go (NEW), pkg/tools/language/executor_test.go (NEW)

Acceptance Criteria

  • Package compiles with go build ./pkg/tools/language/...
  • InferLanguageFromPath correctly maps .py, .js, .ts, .cs, and unknown extensions
  • GetExecutor returns ErrUnsupportedLanguage for JS, TS, DotNet in Phase 1
  • ScriptExecutor interface is compatible with tools.ExecOptions from pkg/tools/script.go
  • All unit tests pass

References

Metadata

Metadata

Assignees

Labels

area/hooksLifecycle hooksarea/toolsExternal tools (Docker, npm, Python)featureFeature request

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions