Skip to content

Commit 64b9140

Browse files
committed
test: add codegen determinism regression test
1 parent e6de470 commit 64b9140

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-FileCopyrightText: 2025 ash_typescript contributors <https://github.com/ash-project/ash_typescript/graphs/contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule AshTypescript.Rpc.CodegenDeterminismTest do
6+
@moduledoc """
7+
Regression test to ensure TypeScript code generation is deterministic.
8+
9+
Runs the codegen multiple times and verifies that the output is identical
10+
across all runs. Non-determinism typically comes from iterating over maps,
11+
MapSets, or unsorted collections derived from Ash.Info.domains().
12+
"""
13+
use ExUnit.Case, async: false
14+
15+
@moduletag :ash_typescript
16+
17+
setup do
18+
Application.put_env(:ash_typescript, :enable_namespace_files, false)
19+
:ok
20+
end
21+
22+
describe "codegen determinism" do
23+
test "generating TypeScript types 10 times produces identical output" do
24+
hashes =
25+
Enum.map(1..10, fn _i ->
26+
{:ok, typescript} =
27+
AshTypescript.Rpc.Codegen.generate_typescript_types(:ash_typescript)
28+
29+
:crypto.hash(:sha256, typescript) |> Base.encode16()
30+
end)
31+
32+
unique_hashes = Enum.uniq(hashes)
33+
34+
assert length(unique_hashes) == 1,
35+
"Expected all 10 runs to produce identical output, but got #{length(unique_hashes)} distinct outputs"
36+
end
37+
end
38+
end

0 commit comments

Comments
 (0)