Skip to content

Commit 6d08e3d

Browse files
committed
fix(gov): consume atomic deployment sources
1 parent 5c417ee commit 6d08e3d

2 files changed

Lines changed: 38 additions & 36 deletions

File tree

keeper/src/keeper/gov/service/upload.lua

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,18 @@ type RegistryEntry = {
2020
}
2121

2222
type SourceAuthority = {
23-
host: boolean,
24-
modules: {[string]: boolean},
25-
roots: {string},
23+
owners: {[string]: boolean},
24+
ordered_owners: {string},
2625
}
2726

2827
function M.retain_authoritative_entries(entries: {RegistryEntry}, authority: SourceAuthority)
2928
local retained: {RegistryEntry} = {}
3029
local skipped = {}
3130
for _, entry in ipairs(entries or {}) do
3231
local module = entry.meta and entry.meta.module
33-
local authoritative = authority.host and (module == nil or module == "")
34-
if type(module) == "string" and module ~= "" then
35-
authoritative = authority.modules[module] == true
36-
end
32+
local owner = "application"
33+
if type(module) == "string" and module ~= "" then owner = module end
34+
local authoritative = authority.owners[owner] == true
3735
if authoritative then
3836
table.insert(retained, entry)
3937
else
@@ -140,15 +138,15 @@ local function add_skip_stats(stats, filesystem_skipped, registry_skipped, manag
140138
return stats
141139
end
142140

143-
local function build_details(managed_namespaces, filesystem_skipped, registry_skipped, unmounted_registry, source_roots)
141+
local function build_details(managed_namespaces, filesystem_skipped, registry_skipped, unmounted_registry, source_owners)
144142
return {
145143
managed_namespaces = managed_namespaces or {},
146144
skipped_unmanaged = {
147145
filesystem = M.skipped_summary(filesystem_skipped),
148146
registry = M.skipped_summary(registry_skipped),
149147
unmounted_registry = M.skipped_summary(unmounted_registry),
150148
},
151-
source_roots = source_roots or {},
149+
source_owners = source_owners or {},
152150
}
153151
end
154152

@@ -210,34 +208,39 @@ end
210208
local function get_filesystem_entries(options)
211209
log:debug("Getting filesystem entries", options)
212210

213-
local source_modules = rawget(system, "source_modules")
214-
local load_sources = rawget(loader, "load_sources")
215-
if (source_modules == nil) ~= (load_sources == nil) then
216-
return nil, nil, nil, nil, "runtime module-source capabilities are incomplete"
217-
end
218-
219-
local authority: SourceAuthority = { host = true, modules = {}, roots = { "application" } }
211+
local source = rawget(system, "source")
212+
local authority: SourceAuthority = {
213+
owners = { application = true },
214+
ordered_owners = { "application" },
215+
}
220216
local all_entries: {RegistryEntry} = {}
221217

222-
if source_modules ~= nil and load_sources ~= nil then
223-
if type(source_modules) ~= "function" or type(load_sources) ~= "function" then
224-
return nil, nil, nil, nil, "runtime module-source capabilities have invalid types"
218+
if source ~= nil then
219+
if type(source) ~= "table" then
220+
return nil, nil, nil, nil, "runtime source capability has an invalid type"
225221
end
226-
local modules, modules_err = source_modules()
227-
if not modules then return nil, nil, nil, nil, tostring(modules_err) end
228-
for _, module in ipairs(modules) do
229-
if type(module) ~= "string" then
230-
return nil, nil, nil, nil, "runtime returned an invalid module-source identifier"
231-
end
232-
local module_name: string = module
233-
authority.modules[module_name] = true
234-
table.insert(authority.roots, module_name)
222+
local load = rawget(source, "load")
223+
if type(load) ~= "function" then
224+
return nil, nil, nil, nil, "runtime source load capability is unavailable"
235225
end
236-
local loaded, load_err = load_sources()
226+
local loaded, load_err = load()
237227
if not loaded then
238228
return nil, nil, nil, nil, "Failed to load deployment sources: " .. tostring(load_err)
239229
end
240-
all_entries = M.retain_authoritative_entries(loaded :: {RegistryEntry}, authority)
230+
if type(loaded.owners) ~= "table" or type(loaded.entries) ~= "table" then
231+
return nil, nil, nil, nil, "runtime returned an invalid deployment source snapshot"
232+
end
233+
authority = { owners = {}, ordered_owners = {} }
234+
for _, owner in ipairs(loaded.owners) do
235+
if type(owner) ~= "string" or owner == "" then
236+
return nil, nil, nil, nil, "runtime returned an invalid source owner"
237+
end
238+
if not authority.owners[owner] then
239+
authority.owners[owner] = true
240+
table.insert(authority.ordered_owners, owner)
241+
end
242+
end
243+
all_entries = M.retain_authoritative_entries(loaded.entries :: {RegistryEntry}, authority)
241244
else
242245
-- Older runtimes expose only the application filesystem. Module-owned
243246
-- snapshots stay outside this sync operation.
@@ -347,7 +350,7 @@ local function has_changes(options)
347350
has_changes = comparison.has_changes,
348351
count = comparison.count,
349352
details = build_details(managed_namespaces, filesystem_skipped, registry_skipped,
350-
unmounted_registry, authority.roots),
353+
unmounted_registry, authority.ordered_owners),
351354
}
352355
end
353356

@@ -399,7 +402,7 @@ local function upload(options)
399402
delete = 0
400403
}, filesystem_skipped, registry_skipped, managed_namespaces, unmounted_registry),
401404
details = build_details(managed_namespaces, filesystem_skipped, registry_skipped,
402-
unmounted_registry, authority.roots),
405+
unmounted_registry, authority.ordered_owners),
403406
}
404407
end
405408

@@ -424,7 +427,7 @@ local function upload(options)
424427
count = comparison.count,
425428
stats = stats,
426429
details = build_details(managed_namespaces, filesystem_skipped, registry_skipped,
427-
unmounted_registry, authority.roots),
430+
unmounted_registry, authority.ordered_owners),
428431
}
429432
end
430433

keeper/src/keeper/gov/service/upload_test.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ local function define_tests()
131131
{ id = "example.packed:item", kind = "registry.entry",
132132
meta = { module = "example/packed" } },
133133
}, {
134-
host = true,
135-
modules = { ["example/local"] = true },
136-
roots = { "application", "example/local" },
134+
owners = { application = true, ["example/local"] = true },
135+
ordered_owners = { "application", "example/local" },
137136
})
138137
test.eq(#retained, 2)
139138
test.eq(retained[1].id, "app:host")

0 commit comments

Comments
 (0)