Language Resolution in HookConfig.validate()
Part of #7435 — Multi-Language Hook Support
User Story
As a template author, I want azd to automatically detect that my seed.py hook is a Python script so I don't have to specify language: python in every hook definition.
Solution Approach
Modify validate() in pkg/ext/models.go. Insert resolveLanguage() step after determining file vs inline, before shell inference:
- If explicit
Language field set → use it, set resolvedLanguage.
- Else if explicit
Shell field set → resolvedLanguage stays Unknown (shell hook).
- Else if file-based → call
language.InferLanguageFromPath(path):
- Recognized language → set
resolvedLanguage.
- Not recognized → fall through to shell inference (existing behavior).
- Else → inline script, fall through to shell inference.
Additional logic:
- If
resolvedLanguage != Unknown AND location == ScriptLocationInline → return error: "inline scripts are not supported for language hooks (language: %s). Use a file path instead."
- If
resolvedLanguage != Unknown → set validated = true, return nil (skip shell inference).
- Update
inferScriptTypeFromFilePath() error message to acknowledge language scripts.
- Update
ErrUnsupportedScriptType error variable for clarity.
Modify pkg/ext/models_test.go — table-driven tests:
.py → ScriptLanguagePython
.js → ScriptLanguageJavaScript
.ts → ScriptLanguageTypeScript
.cs → ScriptLanguageDotNet
.sh → ScriptLanguageUnknown (shell hook)
.ps1 → ScriptLanguageUnknown
- Explicit
language: python with .sh extension → Python (override wins)
- Explicit
shell: sh with .py extension → shell hook (shell wins)
- Inline with
language: python → error
- No extension, no shell, no language → OS default shell
Files: pkg/ext/models.go (MODIFY), pkg/ext/models_test.go (MODIFY)
Acceptance Criteria
References
Language Resolution in HookConfig.validate()
Part of #7435 — Multi-Language Hook Support
User Story
As a template author, I want azd to automatically detect that my
seed.pyhook is a Python script so I don't have to specifylanguage: pythonin every hook definition.Solution Approach
Modify
validate()inpkg/ext/models.go. InsertresolveLanguage()step after determining file vs inline, before shell inference:Languagefield set → use it, setresolvedLanguage.Shellfield set →resolvedLanguagestays Unknown (shell hook).language.InferLanguageFromPath(path):resolvedLanguage.Additional logic:
resolvedLanguage != UnknownANDlocation == ScriptLocationInline→ return error:"inline scripts are not supported for language hooks (language: %s). Use a file path instead."resolvedLanguage != Unknown→ setvalidated = true, return nil (skip shell inference).inferScriptTypeFromFilePath()error message to acknowledge language scripts.ErrUnsupportedScriptTypeerror variable for clarity.Modify
pkg/ext/models_test.go— table-driven tests:.py→ScriptLanguagePython.js→ScriptLanguageJavaScript.ts→ScriptLanguageTypeScript.cs→ScriptLanguageDotNet.sh→ScriptLanguageUnknown(shell hook).ps1→ScriptLanguageUnknownlanguage: pythonwith.shextension → Python (override wins)shell: shwith.pyextension → shell hook (shell wins)language: python→ errorFiles:
pkg/ext/models.go(MODIFY),pkg/ext/models_test.go(MODIFY)Acceptance Criteria
.py,.js,.ts,.csextensionslanguage:field takes precedence over extensionshell:field takes precedence over language inference.sh,.ps1, inline) completely unaffectedReferences