Skip to content

Hook kind inference fails when dir and run are both set without explicit kind #7691

Description

@wbreza

Bug Description

When a hook configuration has both dir and run fields set and no explicit kind, the hook kind inference fails to detect the correct executor. On Windows this causes hooks to default to PowerShell and look for a .ps1 file, even when the actual script is Python, JavaScript, TypeScript, Bash, or C#.

Steps to Reproduce

  1. Configure azure.yaml with a service hook using both dir and run:
    hooks:
      preprovision:
        dir: hooks/preprovision
        run: main.py
  2. Run azd provision on Windows

Expected Behavior

The hook system should infer kind: python from the .py extension on the run field and execute with the Python executor.

Actual Behavior

The hook defaults to PowerShell and fails looking for a .ps1 file. Error: script with file extension '' is not valid. unsupported script type.

Root Cause

In pkg/ext/models.go validate(), when dir + run are combined:

  1. hc.path is set to the raw hc.Run value instead of the resolved filename found via os.Stat
  2. InferKindFromPath receives hc.Run instead of the actual file path with extension
  3. Kind inference fails and defaults to defaultKindForOS() (PowerShell on Windows)

Affected Hook Kinds

All non-shell hook kinds are affected when using dir + run without explicit kind:

  • Python (.py)
  • JavaScript (.js)
  • TypeScript (.ts)
  • C#/DotNet (.cs)
  • Bash (.sh) on Windows

Fix

Fix is being implemented in PR #7689 alongside the path boundary fix for #7666.

Metadata

Metadata

Assignees

Labels

area/hooksLifecycle hooksbugSomething isn't working

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions