Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Test language fallback rows from the pinned engine

thehobbit850264b831e687
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index ad2f156e..3d079b54 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -367,18 +367,19 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
+ - name: Engine (tools/engine.py sync, issue #214)
+ id: sync
+ if: ${{ !cancelled() }}
+ working-directory: .
+ run: python3 tools/engine.py sync
# The views, the host layer (catalogue from embedded frameworks, the engine launch plan, settings, bookmarks) and the
- # controller mapping, on the Mac (the package also builds for macOS); the UI tests need a Simulator and stay local
+ # controller mapping, on the Mac. The language-row contract test reads the synced engine. The UI tests need a Simulator and stay local.
- name: iOS shell package (frontend-ios, swift test)
+ if: ${{ !cancelled() && steps.sync.outcome == 'success' }}
working-directory: frontend-ios
run: |
mkdir -p ../logs
swift test 2>&1 | tee ../logs/shell-package-tests.log
- - name: Engine (tools/engine.py sync, issue #214)
- id: sync
- if: ${{ !cancelled() }}
- working-directory: .
- run: python3 tools/engine.py sync
- name: Host unit tests (dm/host/tests)
if: ${{ !cancelled() && steps.sync.outcome == 'success' }}
run: |
diff --git a/frontend-ios/Tests/ShellHostTests/RomfsLanguagesTests.swift b/frontend-ios/Tests/ShellHostTests/RomfsLanguagesTests.swift
index 2ad53186..029e473e 100644
--- a/frontend-ios/Tests/ShellHostTests/RomfsLanguagesTests.swift
+++ b/frontend-ios/Tests/ShellHostTests/RomfsLanguagesTests.swift
@@ -139,6 +139,43 @@ import Testing
#expect(row.accepts("zh-Hans") && !row.accepts("pt-BR"), "a saved choice the game does not have reads as the default")
}
+ #if os(macOS)
+ /// Generate the row from the pinned engine, rather than trusting the copied JSON fixture (#698).
+ @Test func thePinnedEnginesFallbackRowIsRecognizedAndNarrowed() throws {
+ var root = URL(fileURLWithPath: #filePath)
+ for _ in 0..<4 { root.deleteLastPathComponent() }
+ let dir = try folder(with: Self.image(mask("JPja USen CNzh TWzh EUfr\n01111\n")))
+ defer { try? FileManager.default.removeItem(at: dir) }
+ try Data().write(to: dir.appendingPathComponent("main.fixups.tsv"))
+ let output = dir.appendingPathComponent("launcher.json")
+ let process = Process()
+ process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
+ process.arguments = ["python3", root.appendingPathComponent("engine/dm/games/settings.py").path,
+ "040074A01BF12000", dir.path, dir.appendingPathComponent("missing-control.nacp").path, output.path]
+ process.environment = ["PATH": ProcessInfo.processInfo.environment["PATH"] ?? "/usr/bin:/bin",
+ "SETTINGS_PLATFORM": "ios", "GFXAPI": "nvn", "DM_LANG": "en-US",
+ "PYTHONDONTWRITEBYTECODE": "1", "PYTHONNOUSERSITE": "1"]
+ let pipe = Pipe()
+ process.standardOutput = pipe
+ process.standardError = pipe
+ try process.run()
+ let diagnostic = String(decoding: pipe.fileHandleForReading.readDataToEndOfFile(), as: UTF8.self)
+ process.waitUntilExit()
+ try #require(process.terminationStatus == 0, "Run python3 tools/engine.py sync before testing: \(diagnostic)")
+
+ let profile = try LauncherProfile.parse(Data(contentsOf: output))
+ let emitted = try #require(langRow(profile))
+ #expect(emitted.kind == "choice")
+ #expect(RomfsLanguages.isFallbackRow(emitted))
+ let narrowed = RomfsLanguages.applying(to: profile, options: RomfsLanguages.options(in: dir))
+ let language = try #require(langRow(narrowed))
+ #expect(language.options?.map { $0[0] } == ["en-US", "ja", "fr", "zh-Hant", "zh-Hans"])
+ #expect(language.def == "en-US")
+ #expect(language.note == "")
+ #expect(language.accepts("zh-Hans") && !language.accepts("pt-BR"))
+ }
+ #endif
+
@Test func theRowStaysWhenTheRomFSCannotNarrowIt() throws {
let p = try profile(row: Self.fallbackRowJSON)
for text in ["Hello\n", "USen\n", "JPja EUfr\n"] { // no tag, one language, no American English (the packed default)
diff --git a/frontend/Tests/NX2AppleTests/MacAppLanguageTests.swift b/frontend/Tests/NX2AppleTests/MacAppLanguageTests.swift
index 3fd8e0d3..76224dd5 100644
--- a/frontend/Tests/NX2AppleTests/MacAppLanguageTests.swift
+++ b/frontend/Tests/NX2AppleTests/MacAppLanguageTests.swift
@@ -167,6 +167,37 @@ final class MacAppLanguageTests: IsolatedDefaultsTestCase {
XCTAssertTrue(lang.storeBacked, "the engine's own row stays a saved choice, which the app's launcher reads")
}
+ /// Unlike the copied fixtures, this follows the pin: a changed engine row must still parse and narrow (#698).
+ func testPinnedEngineFallbackRowIsRecognizedAndNarrowedWithoutRewritingTheApp() throws {
+ var root = URL(fileURLWithPath: #filePath)
+ for _ in 0..<4 { root.deleteLastPathComponent() }
+ let output = temporary.appendingPathComponent("engine-launcher.json")
+ try Data().write(to: temporary.appendingPathComponent("main.fixups.tsv"))
+ let result = SystemProcessRunner().capture(ProcessLaunch(
+ executable: "/usr/bin/env",
+ arguments: ["python3", root.appendingPathComponent("engine/dm/games/settings.py").path,
+ "040074A01BF12000", temporary.path, temporary.appendingPathComponent("missing-control.nacp").path, output.path],
+ environment: ["PATH": ProcessInfo.processInfo.environment["PATH"] ?? "/usr/bin:/bin",
+ "SETTINGS_PLATFORM": "mac", "GFXAPI": "nvn", "DM_LANG": "en-US",
+ "PYTHONDONTWRITEBYTECODE": "1", "PYTHONNOUSERSITE": "1"], mergesErrors: true, timeout: 10))
+ XCTAssertTrue(result.ok, "Run python3 tools/engine.py sync before testing: \(result.out)")
+ let generated = try Data(contentsOf: output)
+ let emitted = try XCTUnwrap(LaunchList.parse(generated)?.settings.first { $0.env == "DM_LANG" })
+ XCTAssertEqual(emitted.kind, "choice")
+ XCTAssertTrue(RomFSLanguages.isFallbackRow(options: emitted.options, note: emitted.note))
+
+ let (app, _) = try appWithLangRow(nil, mask: "JPja USen CNzh TWzh EUfr\n01111\n")
+ let launcher = app.appendingPathComponent("Contents/Resources/dm/launcher.json")
+ try generated.write(to: launcher)
+ let language = try XCTUnwrap(LaunchSetting.forMac(app: app.path, titleID: "040074A01BF12000", repo: "", labels: { $0 })?
+ .first { $0.env == "DM_LANG" })
+ XCTAssertEqual(language.options?.map { $0[0] }, ["en-US", "ja", "fr", "zh-Hant", "zh-Hans"])
+ XCTAssertEqual(language.def, "en-US")
+ XCTAssertEqual(language.note, "")
+ // Reading options must not mutate resources inside a signed Mac app.
+ XCTAssertEqual(try Data(contentsOf: launcher), generated)
+ }
+
/// The row is left alone when the RomFS cannot say: no list, one language, or the packed default is not among them.
func testTheAllLanguagesRowStaysWhenTheRomFSCannotNarrowIt() throws {
for mask in ["Hello\n", "USen\n", "JPja EUfr\n"] { // no tag, one language, no American English (the packed default)