mirror of
https://github.com/openai/codex.git
synced 2026-09-20 12:47:38 +00:00
## What changed - Add a Tree-sitter-based lowerer that converts a conservative subset of literal PowerShell commands into argument vectors. - Reject dynamic expressions, parse recovery, unsupported value conversions, directives, and source outside recognized command nodes instead of guessing their meaning. - Keep the lowerer alongside the existing production parser for later adoption. ## Testing - Add fixture-driven coverage for supported literal commands and unsupported or ambiguous syntax, including a dedicated `#requires` rejection test. GitOrigin-RevId: a6e7acc264ca40df264db4b271e38ae7d89e1ec4
38 lines
1011 B
Rust
38 lines
1011 B
Rust
use pretty_assertions::assert_eq;
|
|
use serde::Deserialize;
|
|
|
|
use super::try_parse_powershell_commands;
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct FixtureCase {
|
|
name: String,
|
|
script: String,
|
|
expected: Option<Vec<Vec<String>>>,
|
|
}
|
|
|
|
#[test]
|
|
fn lowers_compact_literal_fixture() {
|
|
// Supported outputs were captured from the PowerShell 7 AST subprocess parser. Rare forms
|
|
// that need additional PowerShell-specific lowering are intentionally recorded as unsupported.
|
|
let cases: Vec<FixtureCase> =
|
|
serde_json::from_str(include_str!("fixtures/powershell_lowering.json"))
|
|
.expect("valid PowerShell lowering fixture");
|
|
|
|
for case in cases {
|
|
assert_eq!(
|
|
try_parse_powershell_commands(&case.script),
|
|
case.expected,
|
|
"fixture case: {}",
|
|
case.name
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn rejects_requires_directives() {
|
|
assert_eq!(
|
|
try_parse_powershell_commands("#requires -Modules Evil\nGet-Location"),
|
|
None
|
|
);
|
|
}
|