feat(minder): match normalised forms of file paths

Description

This MR adds FilePathForms to the tool-call matcher for https://gitlab.com/gitlab-org/gitlab/-/work_items/634679. A file path is matched as sent and also made absolute from the working directory, with a leading ~ expanded, symbolic links resolved, and the file name in its case on disk. For a path that does not exist yet, the deepest existing folder is resolved. On macOS and Windows the paths are also matched in lower case. So a rule anchored at an absolute, lower-case path matches a relative path, a link, or a name typed in another case. The hook in the next MR of the stack uses these forms.

The shared test vectors now expect bash -c "npm publish", env NODE_ENV=production npm publish and a read of ~/.ssh/id_rsa to be denied, per the decision in https://gitlab.com/gitlab-org/gitlab/-/work_items/634683#note_4270141449. With this MR every vector runs through the hook's command and path normalisation, and only Windows vector is skipped. The GitLab side needs the same normalisation, which is tracked in https://gitlab.com/gitlab-org/gitlab/-/work_items/634673.

It is stacked on !4471.

How has this been tested?

Unit tests cover absolute, unclean, and relative paths, ~, symbolic links including a file that does not exist yet, the name on disk, and the lower-case forms. The shared vectors pass through the hook's normalisation, with and without lower-case forms. A benchmark with every vector policy loaded measures about 0.4 to 0.7 ms per call to parse the snapshot, compile it, and decide.

Edited by Jean van der Walt

Merge request reports

Loading
Loading