Skip to content

scripts/meta_to_xml.ps1: a negative -Limit converts nothing and exits 0 (EGEN-META-TO-XML-LIMIT) - #6170

Open
evilclanker9000 wants to merge 3 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/10-meta-to-xml-limit
Open

evilclanker9000 wants to merge 3 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/10-meta-to-xml-limit

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

What

scripts/meta_to_xml.ps1 took -Limit as a plain [int]. In PowerShell any non-zero value is true, so with a negative limit the loop guard if ($Limit -and $n -ge $Limit) is true at $n = 0 and the run stops before the first blob. The script then prints pso ok 0 failed 0; rbf ok 0 failed 0, writes an empty failures.txt, and exits 0: a mistyped limit looks exactly like a carve with no PSO/RBF metadata. (The sibling Python tools fix the same class of bug, e.g. tools/rpf9_carve.py's byte_count docstring.)

The parameter now carries [ValidateRange(0, 2147483647)], so a negative value is refused while the arguments are bound, before Add-Type touches CodeWalker or <Out> is created. 0 keeps its documented meaning of "every blob"; the usage comment now says so.

Test

python -I tests/test_meta_to_xml_paths.py -v — the new tests build the three CodeWalker DLLs as synthetic stand-ins with PowerShell's own compiler (existing BUILD_STUB), so nothing needs CodeWalker, game files or a GPU.

Before the change (script from upstream/main, tests from this PR):

test_negative_limit_is_refused_before_anything_is_converted ... FAIL
AssertionError: 0 == 0 : pso ok 0 failed 0; rbf ok 0 failed 0 -> ...\out
test_plain_bracketed_and_unicode_paths ... ok
test_zero_limit_still_converts_every_blob ... ok
Ran 3 tests ... FAILED (failures=1)

After the change:

test_negative_limit_is_refused_before_anything_is_converted ... ok
test_plain_bracketed_and_unicode_paths ... ok
test_zero_limit_still_converts_every_blob ... ok
Ran 3 tests in 4.7s

OK

With -Limit -5 the script now stops with Cannot validate argument on parameter 'Limit'. The -5 argument is less than the minimum allowed range of 0. and exit status 1, and <Out> is not created.

GPU

No GPU needed: neither the script's parameter binding nor the tests touch a driver.

Notes

  • I kept 0 as "convert every blob" rather than making it invalid, because it is the parameter's default and the only way to say "no limit" today; the usage line now states it.
  • ValidateRange runs at binding time, which is why the refusal happens before the CodeWalker assemblies are loaded — that also made the behaviour testable without CodeWalker.
  • The test file's DLL-stub builder and the two-blob fixture moved to module level so the new tests reuse them; the existing path test keeps the same fixture.

AI-assisted.

A negative value is true in PowerShell, so the loop guard \\ -and \ -ge \\ broke before the first blob: exit 0, 'pso ok 0 failed 0' and an empty failures.txt on a mistyped limit. ValidateRange(0, ...) rejects it at binding time; 0 still means every blob.
…imit bug)

Runs the script against synthesized stand-ins for the three CodeWalker DLLs, so it needs no CodeWalker, no game files and no GPU. The fixture and the DLL stub builder move to module level for reuse; the existing path test keeps its fixture unchanged.
The default 0 must keep meaning 'no limit', so the new range cannot turn the documented default into a refusal.
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested a5ddf0c5 on Windows with PowerShell 5.1 and synthetic DLLs. All three tests in py -3.14 -I tests/test_meta_to_xml_paths.py pass. On merge base 561b65a8, the new -Limit -5 test fails because the script returns success. The positive-limit control converts exactly one blob.

A separate performance observation for -Limit 1: I kept the first blob constant and changed only the size of its archive index. With 100 rows the PowerShell process peaked at 90,771,456 bytes of working set. With 30,000 rows it peaked at 255,533,056 bytes. With 100 rows again it peaked at 90,734,592 bytes. Every run converted one blob. The parent shows the same growth.

ConvertFrom-Json reads the entire index. The Where-Object assignment also collects every matching row before the loop checks the limit. Iterating the decoded rows directly and stopping after the first match avoids that second collection. Bounding memory for the index itself would require incremental parsing. These are whole-process measurements, so they do not isolate the cost of either step.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants