File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments