Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

Merge current main and verify PowerShell foreach classification

affaan-m1394cf6f0a68
diff --cc tests/lib/powershell-destructive-command.test.js
index e4f7210ba,43f01994a..16562ef2c
--- a/tests/lib/powershell-destructive-command.test.js
+++ b/tests/lib/powershell-destructive-command.test.js
@@@ -472,27 -472,6 +472,56 @@@ test('classifies invoked functions and
for (const command of commands) expectRules(command, [RULES.REMOVE_FORCE]);
});
+test('distinguishes foreach statements from the pipeline alias', () => {
+ for (const command of [
+ "foreach ($r in 'aaaaaaaaaaaaa') { $r }",
+ "foreach ($r in 'aaaaaaaaaaaaaa') { $r }",
+ "foreach ($s in 'BTCUSDT','ETHUSDT','SOLUSDT') { $s }",
+ ]) {
+ expectSafe(command);
+ }
+
+ expectRules(
+ "foreach ($r in 'aaaaaaaaaaaaaa') { Remove-Item -Force C:/tmp/demo }",
+ [RULES.REMOVE_FORCE]
+ );
+ expectRules('1 | foreach { Remove-Item -Force C:/tmp/demo }', [
+ RULES.REMOVE_FORCE,
+ ]);
+ expectRules('1 | foreach ({ Remove-Item -Force C:/tmp/demo })', [
+ RULES.REMOVE_FORCE,
+ ]);
+});
+
++test('foreach headers and nested bodies retain destructive scanning', () => {
++ for (const command of [
++ 'foreach ($x in $(Remove-Item -Force C:/tmp/demo)) { $x }',
++ 'foreach ($x in (Remove-Item -Force C:/tmp/demo)) { $x }',
++ 'FoReAcH \n ($x in @("a")) { Remove-Item -Force C:/tmp/demo }',
++ 'Get-Date; foreach ($x in "a") { foreach ($y in "b") { Remove-Item -Force C:/tmp/demo } }',
++ ]) expectRules(command, [RULES.REMOVE_FORCE]);
++ for (const command of [
++ 'FoReAcH \n ($x in @("a", "b")) { $x }',
++ 'Get-Date; foreach ($x in "a") { $x }',
++ 'foreach ($x in @({ Remove-Item -Force C:/tmp/demo })) { $x }',
++ 'Write-Output "foreach ($x in Remove-Item -Force C:/tmp/demo)"',
++ ]) expectSafe(command);
++});
++
++test('short dynamic groups preserve following command boundaries', () => {
++ for (const command of [
++ 'iex ($a)\nRemove-Item -Force C:/tmp/demo',
++ 'iex ($a) | Remove-Item -Force C:/tmp/demo',
++ '& ($a); iex ($b); Remove-Item -Force C:/tmp/demo',
++ ]) expectRules(command, [RULES.DYNAMIC_EXECUTION, RULES.REMOVE_FORCE]);
++});
++
++test('resolved scalar output longer than its group preserves following commands', () => {
++ expectRules("$name='Remove-Item'; & $($name) -Force C:/tmp/demo; Clear-Content C:/tmp/demo", [
++ RULES.REMOVE_FORCE, RULES.CLEAR_CONTENT,
++ ]);
++});
++
test('classifies invoked static script-block variables but leaves assignments inert', () => {
expectSafe('$cleanup = { Remove-Item -Force C:/tmp/demo }');
expectRules('$cleanup = { Remove-Item -Force C:/tmp/demo }; & $cleanup', [