mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-27 00:48:32 +02:00
fix(mod-api): harden imported dataset views
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
-- Dedicated Route B no-mod parity: the additive facade remains cold.
|
||||
package.path = "./?.lua;./?/init.lua;" .. package.path
|
||||
local T = require("tests.modkit")
|
||||
|
||||
local reads = 0
|
||||
local fs = T.sdk.memfs({})
|
||||
local read = fs.read
|
||||
fs.read = function(path)
|
||||
if path:match("^[a-z]+/data/generated/")
|
||||
or path:match("^[a-z]+/rom%-cache%.complete$") then
|
||||
reads = reads + 1
|
||||
end
|
||||
return read(path)
|
||||
end
|
||||
local data = { pokemon = { ACTIVE = { id = "ACTIVE", nested = { n = 1 } } } }
|
||||
local run = T.sdk.loadNone({ fs = fs, data = data, generation = 1 })
|
||||
T.eq(#run.errors, 0, "no-mod load remains clean")
|
||||
T.eq(run.loader.datasetViews, nil, "no-mod load does not allocate dataset service")
|
||||
T.eq(reads, 0, "no-mod load performs no imported dataset reads")
|
||||
T.eq(data.pokemon.ACTIVE.nested.n, 1, "no-mod data remains unchanged")
|
||||
run.release()
|
||||
T.finish("dataset_views_no_mod_parity")
|
||||
@@ -0,0 +1,37 @@
|
||||
-- Restricted generated-data grammar and resource limits.
|
||||
package.path = "./?.lua;./?/init.lua;" .. package.path
|
||||
local T = require("tests.modkit")
|
||||
local SaveSerializer = require("src.core.SaveSerializer")
|
||||
|
||||
local limits = {
|
||||
allowArray = true, allowComments = true,
|
||||
maxBytes = 256, maxDepth = 4, maxNodes = 7,
|
||||
maxStringBytes = 8, maxTableEntries = 5, rootName = "generated data",
|
||||
}
|
||||
|
||||
local value, err = SaveSerializer.decode(
|
||||
'-- Generated by tools/build_data.py. DO NOT EDIT.\n'
|
||||
.. 'return { rows = { "A", "B" }, [3] = true }\n', limits)
|
||||
T.same(value, { rows = { "A", "B" }, [3] = true },
|
||||
"LuaWriter array and keyed-table grammar decodes as data")
|
||||
T.eq(err, nil, "valid generated data has no error")
|
||||
|
||||
local invalid = {
|
||||
{ "return function() end", "function literal" },
|
||||
{ "owned = true; return {}", "global assignment" },
|
||||
{ "return {}; print('x')", "trailing executable syntax" },
|
||||
{ string.char(27) .. "Lua", "binary chunk" },
|
||||
{ "return " .. string.rep(" ", 260) .. "{}", "source-size limit" },
|
||||
{ 'return { a = { b = { c = { d = { e = {} } } } } }', "depth limit" },
|
||||
{ 'return { a = "123456789" }', "string limit" },
|
||||
{ 'return { 1, 2, 3, 4, 5, 6 }', "table-entry limit" },
|
||||
{ 'return { a = 1, b = 2, c = 3, d = 4, e = { f = 6, g = 7 } }',
|
||||
"node limit" },
|
||||
{ "return 7", "non-table root" },
|
||||
}
|
||||
for _, row in ipairs(invalid) do
|
||||
local got = SaveSerializer.decode(row[1], limits)
|
||||
T.eq(got, nil, row[2] .. " fails closed")
|
||||
end
|
||||
|
||||
T.finish("generated_data_decoder")
|
||||
@@ -1,32 +1,36 @@
|
||||
-- sourceTreeHasData must use each version's required-file list. Gold's
|
||||
-- cache has no Gen 1 trade art / pikachu.png; validating it against
|
||||
-- REQUIRED_FILES made a Gold source tree look incomplete forever.
|
||||
-- Shared cache readiness uses the selected version's source-tree contract.
|
||||
package.path = "./?.lua;./?/init.lua;" .. package.path
|
||||
|
||||
local T = require("tests.harness")
|
||||
local check = T.check
|
||||
local CacheContract = require("src.import.CacheContract")
|
||||
local GameVersion = require("src.core.GameVersion")
|
||||
|
||||
local f = assert(io.open("src/import/RomImporter.lua", "r"))
|
||||
local src = f:read("*a")
|
||||
f:close()
|
||||
local present = {}
|
||||
for _, path in ipairs(CacheContract.requiredFiles("gold")) do
|
||||
present[GameVersion.cachePrefix("gold") .. path] = true
|
||||
end
|
||||
local fs = {
|
||||
read = function() return nil end,
|
||||
getInfo = function(path) return present[path] and { type = "file" } or nil end,
|
||||
getRealDirectory = function(path) return present[path] and "/source" or nil end,
|
||||
getSource = function() return "/source" end,
|
||||
}
|
||||
|
||||
local start = src:find("local function sourceTreeHasData", 1, true)
|
||||
check(start ~= nil, "sourceTreeHasData is defined")
|
||||
local finish = src:find("\nfunction RomImporter.isReady", start, true)
|
||||
check(finish ~= nil, "sourceTreeHasData ends before isReady")
|
||||
local body = src:sub(start, finish)
|
||||
local inspected = CacheContract.inspect("gold", fs, { allowSource = true })
|
||||
T.eq(inspected and inspected.kind, "source",
|
||||
"Gold source tree uses Gold's required-file contract")
|
||||
|
||||
check(body:find("requiredFilesFor", 1, true) ~= nil,
|
||||
"sourceTreeHasData uses requiredFilesFor (Gold override, not Gen 1 only)")
|
||||
check(body:find("ipairs(REQUIRED_FILES)", 1, true) == nil,
|
||||
"sourceTreeHasData does not iterate the Gen 1 REQUIRED_FILES list raw")
|
||||
present["gold/assets/generated/battle/hud/balls.png"] = nil
|
||||
T.eq(CacheContract.inspect("gold", fs, { allowSource = true }), nil,
|
||||
"missing Gold-only trainer HUD asset makes the source tree incomplete")
|
||||
|
||||
local helperStart = src:find("local function requiredFilesFor", 1, true)
|
||||
check(helperStart ~= nil, "requiredFilesFor helper exists")
|
||||
local helper = src:sub(helperStart, start)
|
||||
check(helper:find("VERSION_REQUIRED_FILES_OVERRIDE", 1, true) ~= nil,
|
||||
"requiredFilesFor consults VERSION_REQUIRED_FILES_OVERRIDE")
|
||||
check(src:find('"assets/generated/battle/hud/balls.png"', 1, true) ~= nil,
|
||||
"Gold caches require the trainer HUD ball sheet")
|
||||
local required = {}
|
||||
for _, path in ipairs(CacheContract.requiredFiles("gold")) do required[path] = true end
|
||||
T.eq(required["data/generated/rom_text.lua"], true,
|
||||
"Gold requires generated ROM text")
|
||||
T.eq(required["assets/generated/pc/mail_item.png"], true,
|
||||
"Gold requires PC mail art")
|
||||
T.eq(required["assets/generated/trade/game_boy.png"], nil,
|
||||
"Gold does not inherit the Gen 1 trade-art contract")
|
||||
|
||||
T.finish()
|
||||
|
||||
@@ -83,16 +83,12 @@ if extractor then
|
||||
"field.lua publishes tradeArt")
|
||||
end
|
||||
|
||||
-- a cache imported before #750 has none of the art; listing one of the
|
||||
-- files in REQUIRED_FILES is what makes it re-import
|
||||
local importer = readFile("src/import/RomImporter.lua")
|
||||
T.check(importer ~= nil, "src/import/RomImporter.lua is readable")
|
||||
if importer then
|
||||
local required = importer:match("local REQUIRED_FILES = {(.-)\n}")
|
||||
T.check(required ~= nil, "REQUIRED_FILES parses")
|
||||
T.check(required ~= nil and required:find(
|
||||
'"assets/generated/trade/game_boy.png"', 1, true) ~= nil,
|
||||
"REQUIRED_FILES makes pre-#750 caches re-import the trade art")
|
||||
end
|
||||
-- a cache imported before #750 has none of the art; the shared readiness
|
||||
-- contract is what makes it re-import.
|
||||
local CacheContract = require("src.import.CacheContract")
|
||||
local required = {}
|
||||
for _, path in ipairs(CacheContract.requiredFiles("red")) do required[path] = true end
|
||||
T.eq(required["assets/generated/trade/game_boy.png"], true,
|
||||
"required-file contract makes pre-#750 caches re-import the trade art")
|
||||
|
||||
T.finish("trade art import")
|
||||
|
||||
Reference in New Issue
Block a user