367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
521 lines
31 KiB
Python
521 lines
31 KiB
Python
#!/usr/bin/env python3
|
|
"""Stage qualified Classic data through fixed, existing pure producers.
|
|
|
|
This adapter changes data fields and relationships, never native asset bodies.
|
|
Original REA references and Source/native inputs are immutable batch inputs.
|
|
A successful stage is scoped offline evidence, not native/gameplay acceptance.
|
|
"""
|
|
import argparse
|
|
from copy import deepcopy
|
|
import inspect
|
|
import json
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
from map_conversion_batch import Inputs, digest, encoded, require
|
|
import item_basic_compat as basic
|
|
import item_sparse_compat as sparse
|
|
import item_armor_compat as armor
|
|
import item_set_compat as sets
|
|
import item_set_relationship_compat as set_links
|
|
import item_appearance_preflight as appearance
|
|
import item_batch_stage as item_batch
|
|
import item_catalog_stage as item_catalog
|
|
import item_property_catalogue as item_properties
|
|
import source_race_class_creation as races
|
|
import source_starting_outfit_compat as outfits
|
|
import spell_passive_compat as passive
|
|
import spell_restore_compat as restore
|
|
import spell_item_static_compat as static
|
|
import spell_item_proc_compat as proc
|
|
import spell_item_food_regen_compat as food
|
|
import spell_item_mana_regen_compat as mana
|
|
import spell_item_school_crit_compat as crit
|
|
import spell_item_enchantment_compat as enchant
|
|
import spell_active_warrior_compat as warrior
|
|
import spell_shield_slam_compat as shield
|
|
import spell_crafting_compat as crafting
|
|
import spell_visual_compat as visual
|
|
import spell_sound_compat as sound
|
|
import spell_set_modifier_compat as modifier
|
|
import spell_affect_compat as affect
|
|
import content_package_stage as content
|
|
import active_warrior_package_stage as warrior_stage
|
|
import aura_definition_profile as aura
|
|
import aura_source_family_profile as aura_family
|
|
import aura_disarm_profile as aura_disarm
|
|
import aura_visual_profile as aura_visual
|
|
import faction_compat as faction
|
|
import item_enchantment_visual_profile as enchant_visual
|
|
|
|
POLICY = 'qualified-data-only-native-assets-preserved-v1'
|
|
|
|
|
|
def compose_aura_source_family(profile, review):
|
|
"""Stage the existing reviewed mask merge; never publish or infer new aura roles."""
|
|
merged, audit = aura_family.extend(profile, review)
|
|
return {'kind': 'reviewed-aura-source-family-profile-candidate-v1',
|
|
'profile': merged, 'merge': audit, 'native_accepted': False,
|
|
'gameplay_verified': False, 'installed': False}
|
|
|
|
|
|
def compose_aura_disarm_family(profile, source, native, *, enum_proof, native_parent_ids):
|
|
"""Use the existing named-enum disarm review and retain prior aura masks."""
|
|
require(isinstance(native_parent_ids, list)
|
|
and all(type(i) is int and 0 < i <= 0x7fffffff for i in native_parent_ids)
|
|
and len(set(native_parent_ids)) == len(native_parent_ids),
|
|
'Distinct native disarm parent identities required')
|
|
merged, review, audit = aura_disarm.compose(profile, source, native,
|
|
enum_proof=enum_proof,
|
|
native_parent_ids=set(native_parent_ids))
|
|
require(not audit['conflicts'], 'Disarm family conflicts with retained aura masks')
|
|
return {'kind': 'reviewed-aura-disarm-family-profile-candidate-v1',
|
|
'profile': merged, 'review': review, 'merge': audit,
|
|
'native_accepted': False, 'gameplay_verified': False, 'installed': False}
|
|
|
|
|
|
def faction_definitions(source, native, registry, schema):
|
|
"""Stage existing source reputation definitions without inventing race aliases."""
|
|
require(isinstance(source, list) and 0 < len(source) <= 4096
|
|
and isinstance(native, list) and 0 < len(native) <= 4096,
|
|
'Bounded source/native faction definitions required')
|
|
records, mapping = faction.convert(source, native, [], registry, schema)
|
|
return {'kind': 'source-reputation-definition-candidate-v1', 'records': records,
|
|
'mapping': mapping, 'race_aliases_applied': False,
|
|
'native_accepted': False, 'gameplay_verified': False, 'installed': False}
|
|
HELD = {
|
|
'talents': 'No qualified pure talent-table writer: existing export/UI observation does not establish an original consumer conversion contract.',
|
|
'quests': 'No qualified pure quest writer: quest definitions/dialogue require the owning observed protocol/data consumer contract.',
|
|
'npc': 'No qualified pure NPC/dialogue writer: movement observations do not establish a dialogue/definition conversion contract.',
|
|
'ui': 'No qualified pure UI writer: native observations and arbitrary UI script replacement do not establish a data conversion contract.',
|
|
}
|
|
|
|
|
|
def property_catalogue_assessment(catalogue, package, native_effects, native_links, native_names,
|
|
definition_ledger, source_sets, *, reviewed_proc_ids=frozenset(),
|
|
obtainability_reference=None):
|
|
"""Expose the existing whole-catalogue join without publishing records.
|
|
|
|
JSON object keys are strings, while the existing producer compares integer
|
|
spell IDs. Admit only canonical positive decimal keys and preserve the
|
|
producer's independent definition and mechanic gates.
|
|
"""
|
|
if not isinstance(definition_ledger, dict):
|
|
raise ValueError('Source spell-definition ledger must be a mapping')
|
|
ledger = {}
|
|
for raw, value in definition_ledger.items():
|
|
if type(raw) is int:
|
|
ident = raw
|
|
elif isinstance(raw, str) and raw.isascii() and raw.isdecimal() and str(int(raw)) == raw:
|
|
ident = int(raw)
|
|
else:
|
|
raise ValueError('Canonical spell-definition ID required')
|
|
if ident <= 0 or ident >= 0x80000000 or ident in ledger or not isinstance(value, dict):
|
|
raise ValueError('Distinct bounded spell-definition IDs required')
|
|
ledger[ident] = value
|
|
result = item_properties.join_catalogue(catalogue, package, native_effects, native_links,
|
|
native_names, ledger, source_sets,
|
|
reviewed_proc_ids=reviewed_proc_ids,
|
|
obtainability_reference=obtainability_reference)
|
|
result['known_spell_ids'] = sorted(result['known_spell_ids'])
|
|
result.update(kind='item-property-catalogue-assessment-v1', installed=False,
|
|
native_verified=False, gameplay_verified=False,
|
|
package_modified=False, definition_semantics_completed=False)
|
|
return result
|
|
|
|
|
|
def appearance_links(source, target, package, registry, native_max, **options):
|
|
"""Use the existing exact Source display/native witness and package stager."""
|
|
allowed = set(inspect.signature(appearance.missing_weapon_links).parameters) - {
|
|
'source', 'target', 'package_rows', 'registry', 'native_max'}
|
|
require(set(options) <= allowed, 'Unsupported appearance staging option')
|
|
component = appearance.missing_weapon_links(source, target, package['rows'], registry, native_max, **options)
|
|
require(component['records'], 'No exact native appearance links qualified; see existing witness/dependency holds')
|
|
return {'component': component, 'package': appearance.compose_weapon_links(package, component)}
|
|
|
|
|
|
def starting_outfits(requested_pairs, starting_rows, item_snapshot, loadouts, loadout_items,
|
|
native_items, native_sparse, native_appearances, *, parent_max, child_max,
|
|
overlay_rows=()):
|
|
assessment = outfits.derive(requested_pairs, starting_rows, item_snapshot, loadouts,
|
|
loadout_items, native_items, native_sparse, native_appearances)
|
|
rows = outfits.new_records(assessment, parent_max, child_max, overlay_rows)
|
|
return {'assessment': assessment, 'records': [{'table_name': t, 'record': r} for t, r in rows]}
|
|
|
|
|
|
def creation_rows(source_pairs, server_pairs, start_tables, native_rows, *, max_id):
|
|
assessment = races.derive(source_pairs, server_pairs, start_tables, native_rows)
|
|
return {'assessment': assessment, 'records': races.additive_char_base_rows(assessment, native_rows, max_id)}
|
|
|
|
|
|
# Fixed callable objects only. No producer name from an input can import code,
|
|
# run a command, read a database, or call a CLI with hidden default paths.
|
|
# True means the producer can stage an override and requires pinned old rows.
|
|
ADAPTERS = {
|
|
'items.basic': (basic.record, True),
|
|
'items.equipment': (basic.equipment_record, True),
|
|
'items.catalog-identity': (basic.catalog_record, True),
|
|
'items.sparse': (sparse.convert, True),
|
|
'items.armor': (armor.generate, True),
|
|
'items.sets': (sets.generate, True),
|
|
'items.set-relationships': (set_links.compose, True),
|
|
'items.material-retention': (item_batch.compose_material_retention_batch, True),
|
|
'items.accessory-batch': (item_batch.compose_accessory_batch, True),
|
|
'items.passive-equipment-batch': (item_batch.compose_passive_equipment_batch, True),
|
|
'items.plain-armor-batch': (item_batch.compose_plain_armor_batch, True),
|
|
'items.intrinsic-armor-batch': (item_catalog.compose_intrinsic_armor_batch, True),
|
|
'items.catalog-metadata-batch': (item_catalog.compose_metadata_batch, True),
|
|
'items.property-catalogue-assessment': (property_catalogue_assessment, False),
|
|
'equipment.native-appearance-links': (appearance_links, False),
|
|
'equipment.missing-native-links': (appearance.missing_weapon_links, False),
|
|
'equipment.compose-native-links': (appearance.compose_weapon_links, False),
|
|
'equipment.enchantment-visual-candidates': (enchant_visual.generate, False),
|
|
'races.creation-rows': (creation_rows, False),
|
|
'races.starting-outfits': (starting_outfits, False),
|
|
'spells.passive': (passive.component, True),
|
|
'spells.passive-new': (passive.new_component, True),
|
|
'spells.constant': (passive.constant_component, True),
|
|
'spells.restore': (restore.component, True),
|
|
'spells.restore-new': (restore.new_component, True),
|
|
'spells.static': (static.component, True),
|
|
'spells.static-new': (static.new_static_component, True),
|
|
'spells.skill-new': (static.new_skill_component, True),
|
|
'spells.proc-existing': (proc.existing_restoration_component, True),
|
|
'spells.extra-attack-existing': (proc.existing_extra_attack_component, True),
|
|
'spells.proc-new': (proc.new_component, True),
|
|
'spells.food-regen': (food.component, True),
|
|
'spells.mana-regen': (mana.component, True),
|
|
'spells.school-crit': (crit.component, True),
|
|
'spells.enchantment': (enchant.positive, True),
|
|
'spells.concussion-blow': (warrior.concussion_records, True),
|
|
'spells.shield-slam': (shield.records, True),
|
|
'spells.crafting-rows': (crafting.component_rows, True),
|
|
'spells.visual': (visual.new_visual_candidate, True),
|
|
'spells.visual-state': (visual.new_state_visual_candidate, True),
|
|
'spells.visual-hand-attachment': (visual.remap_hand_attachment_kit, True),
|
|
'spells.sound': (sound.new_sound_candidate, True),
|
|
'spells.affect': (affect.derive, True),
|
|
'spells.package-passive': (content.compose, True),
|
|
'spells.package-crafting': (content.compose_crafting, True),
|
|
'spells.package-proc': (content.compose_existing_proc_corrections, True),
|
|
'spells.package-warrior': (warrior_stage.compose, True),
|
|
'auras.definitions': (aura.generate, False),
|
|
'auras.mounts': (aura.generate_mounts, False),
|
|
'auras.ghosts': (aura.generate_ghosts, False),
|
|
'auras.scalar-rows': (aura.attack_power_scalar_rows, True),
|
|
'auras.source-family': (aura_family.generate, False),
|
|
'auras.source-family-merge': (compose_aura_source_family, False),
|
|
'auras.disarm-family-merge': (compose_aura_disarm_family, False),
|
|
'auras.visual-link-candidates': (aura_visual.generate, False),
|
|
'reputation.factions': (faction_definitions, True),
|
|
}
|
|
|
|
|
|
def pointer(value, path):
|
|
require(isinstance(path, str) and (not path or path.startswith('/')), 'JSON pointer required')
|
|
for name in path.split('/')[1:] if path else ():
|
|
name = name.replace('~1', '/').replace('~0', '~')
|
|
if isinstance(value, list):
|
|
require(name.isdecimal() and str(int(name)) == name, 'Canonical array index required')
|
|
value = value[int(name)]
|
|
else:
|
|
require(isinstance(value, dict), 'JSON pointer container required')
|
|
value = value[name]
|
|
return value
|
|
|
|
|
|
def qualified_contract(contract, operation, inputs):
|
|
require(isinstance(contract, dict) and contract.get('policy') == POLICY, 'Qualified data-only policy required')
|
|
require(operation in contract.get('operations', []), 'Operation is outside the qualified contract')
|
|
proofs = contract.get('provenance')
|
|
require(isinstance(proofs, list) and 1 <= len(proofs) <= 64, 'Original REA consumer provenance required')
|
|
for proof in proofs:
|
|
inputs.read(proof, 16 * 1024 * 1024)
|
|
raw = inputs.read(contract.get('receipt'), 16 * 1024 * 1024)
|
|
receipt = json.loads(raw)
|
|
require(isinstance(receipt, dict), 'Qualified receipt object required')
|
|
require('accepted_status' in contract or 'accepted_kind' in contract, 'Exact accepted receipt identity required')
|
|
if 'accepted_status' in contract:
|
|
status = receipt.get('status')
|
|
require(isinstance(status, str) and status == contract['accepted_status'] and
|
|
status.startswith(('PASS_', 'QUALIFIED_', 'COMPLETE_')), 'Qualified receipt status differs')
|
|
if 'accepted_kind' in contract:
|
|
require(receipt.get('kind') == contract['accepted_kind'], 'Qualified receipt kind differs')
|
|
return {'receipt_sha256': contract['receipt']['sha256'], 'provenance': proofs, 'policy': POLICY}
|
|
|
|
|
|
def item_result_denominators(operation, value):
|
|
"""Project the two qualified item producers' actual record outcomes.
|
|
|
|
These are per-job source-record counts, never completion estimates for a
|
|
catalogue or sums across jobs that may request the same source identities.
|
|
Preserving an existing override does not requalify its Source equivalence.
|
|
"""
|
|
if operation not in ('items.catalog-metadata-batch','items.material-retention'):
|
|
return None
|
|
unknown=dict(unit='source-item-record',denominator_known=False,
|
|
reason='Qualified producer record-count envelope unavailable',
|
|
native_acceptance_verified=False)
|
|
if not isinstance(value,dict):return unknown
|
|
added=value.get('added')
|
|
if not isinstance(added,list):return unknown
|
|
if operation=='items.catalog-metadata-batch':
|
|
changed=value.get('selected');excluded=value.get('excluded')
|
|
if not isinstance(changed,list)or not isinstance(excluded,list)or any(not isinstance(r,dict)or not isinstance(r.get('reason'),str)for r in excluded):return unknown
|
|
preserved=sum(r['reason']=='existing-override-preserved'for r in excluded)
|
|
held=len(excluded)-preserved;exact=0;scope=len(changed)+len(excluded)
|
|
else:
|
|
changed=value.get('accepted');excluded=value.get('held');exact_rows=value.get('already_exact');scope=value.get('scope')
|
|
if not all(isinstance(r,list)for r in (changed,excluded,exact_rows))or type(scope)is not int or scope<0:return unknown
|
|
preserved=0;held=len(excluded);exact=len(exact_rows)
|
|
classified=len(changed)+preserved+held+exact
|
|
if classified>scope:return unknown
|
|
return dict(unit='source-item-record',denominator_known=True,denominator=scope,
|
|
qualified_changed_records=len(changed),native_exact_unchanged_records=exact,
|
|
preserved_unrequalified_records=preserved,content_held_records=held,
|
|
unclassified_records=scope-classified,emitted_metadata_rows=len(added),
|
|
aggregation='Per job only; source identities may overlap other jobs',
|
|
native_acceptance_verified=False)
|
|
|
|
|
|
def run_batch(request, *, action='plan', output=None, base_directory=None):
|
|
require(action in ('plan', 'convert'), 'Plan or convert action required')
|
|
if isinstance(request, dict):
|
|
raw = encoded(request)
|
|
base = Path(base_directory or Path.cwd()).resolve()
|
|
else:
|
|
path = Path(request)
|
|
require(path.is_file() and not path.is_symlink() and path.stat().st_size <= 8 * 1024 * 1024,
|
|
'Bounded immutable request file required')
|
|
raw = path.read_bytes()
|
|
base = path.resolve().parent
|
|
require(len(raw) <= 8 * 1024 * 1024, 'Bounded request required')
|
|
manifest = json.loads(raw)
|
|
require(manifest.get('kind') == 'classic-data-batch-v1', 'classic-data-batch-v1 required')
|
|
jobs, refs, contracts = manifest.get('jobs'), manifest.get('inputs'), manifest.get('contracts')
|
|
require(isinstance(jobs, list) and 1 <= len(jobs) <= 4096 and
|
|
all(isinstance(j, dict) and isinstance(j.get('id'), str) for j in jobs) and
|
|
len({j['id'] for j in jobs}) == len(jobs), 'Distinct bounded data jobs required')
|
|
require(isinstance(refs, dict) and isinstance(contracts, dict), 'Named inputs and contracts required')
|
|
target = Path(output) if output is not None else None
|
|
require(action != 'convert' or target is not None, 'Fresh conversion output required')
|
|
if target is not None:
|
|
require(not target.exists() and not target.is_symlink(), 'New immutable output directory required')
|
|
target.mkdir(mode=0o700, parents=True)
|
|
(target / 'input-manifest.json').write_bytes(raw)
|
|
cache = Inputs(base)
|
|
documents, previous, converted, refused, contract_cache = {}, {}, {}, {}, {}
|
|
previous_inputs = {}
|
|
results = []
|
|
|
|
def document(name):
|
|
require(isinstance(name, str) and name in refs, 'Declared input reference required')
|
|
if name not in documents:
|
|
# A coherent full-catalogue metadata package is already 100 MiB;
|
|
# retain explicit file/aggregate guards while admitting that actual
|
|
# registered input rather than the old small-fixture default.
|
|
documents[name] = json.loads(cache.read(refs[name],128*1024*1024))
|
|
return documents[name]
|
|
|
|
def resolve(value, used, result_dependencies):
|
|
if isinstance(value, list):
|
|
return [resolve(v, used, result_dependencies) for v in value]
|
|
if not isinstance(value, dict):
|
|
return value
|
|
if '$concat' in value:
|
|
require(set(value)=={'$concat'} and isinstance(value['$concat'],list) and 1<=len(value['$concat'])<=128,
|
|
'Bounded concatenation of pinned list inputs required')
|
|
result=[]
|
|
for member in value['$concat']:
|
|
rows=resolve(member,used,result_dependencies)
|
|
require(isinstance(rows,list),'Concatenated input must resolve to a list')
|
|
require(len(result)+len(rows)<=262144,'Concatenated catalogue row bound')
|
|
result.extend(rows)
|
|
return result
|
|
if '$input' in value or '$result' in value:
|
|
require(set(value) <= {'$input', '$result', 'pointer', 'as'} and
|
|
(('$input' in value) != ('$result' in value)), 'Exact argument reference required')
|
|
if '$input' in value:
|
|
name = value['$input']; used.add(name)
|
|
selected = document(name)
|
|
else:
|
|
name = value['$result']; result_dependencies.add(name)
|
|
require(name in previous, 'Earlier staged dependency unavailable')
|
|
used.update(previous_inputs[name])
|
|
selected = previous[name]
|
|
selected = deepcopy(pointer(selected, value.get('pointer', '')))
|
|
kind = value.get('as')
|
|
if kind == 'int-key-map':
|
|
require(isinstance(selected, dict) and all(isinstance(k, str) and k.isdecimal() and str(int(k)) == k for k in selected),
|
|
'Canonical decimal-key map required')
|
|
selected = {int(k): v for k, v in selected.items()}
|
|
elif kind == 'set':
|
|
require(isinstance(selected, list) and all(type(v) is int for v in selected), 'Integer identity set required')
|
|
selected = set(selected)
|
|
elif kind == 'dbc':
|
|
require(isinstance(selected, dict) and isinstance(selected.get('rows'), dict) and
|
|
isinstance(selected.get('strings', {}), dict), 'Pinned DBC JSON view required')
|
|
by_id = {int(k): tuple(v) for k, v in selected['rows'].items()}
|
|
strings = {int(k): v for k, v in selected.get('strings', {}).items()}
|
|
require(all(str(k) in selected['rows'] and type(k) is int for k in by_id) and
|
|
all(isinstance(v, str) for v in strings.values()), 'Canonical DBC JSON identities required')
|
|
selected = SimpleNamespace(by_id=by_id, rows=list(by_id.values()),
|
|
fields=selected.get('fields'), string=strings.__getitem__)
|
|
elif kind == 'byte-reader':
|
|
require(isinstance(selected, dict) and all(isinstance(k, str) and isinstance(v, str) and v in refs
|
|
for k, v in selected.items()), 'Exact member-to-declared-input reader required')
|
|
bodies = {k: cache.read(refs[v]) for k, v in selected.items()}
|
|
used.update(selected.values())
|
|
selected = bodies.__getitem__
|
|
else:
|
|
require(kind is None, 'Unsupported argument representation')
|
|
return selected
|
|
return {k: resolve(v, used, result_dependencies) for k, v in value.items()}
|
|
|
|
for job in jobs:
|
|
row = {'id': job['id'], 'operation': job.get('operation'), 'installed': False, 'native_verified': False}
|
|
try:
|
|
operation = job.get('operation')
|
|
require(operation not in HELD, HELD.get(operation, 'Unsupported data operation'))
|
|
require(operation in ADAPTERS, 'No fixed qualified producer for this operation')
|
|
function, can_override = ADAPTERS[operation]
|
|
key = (job.get('contract'), operation)
|
|
require(key[0] in contracts, 'Declared qualified contract required')
|
|
if key not in contract_cache:
|
|
contract_cache[key] = qualified_contract(contracts[key[0]], operation, cache)
|
|
row['contract'] = contract_cache[key]
|
|
used, dependencies = set(), set()
|
|
args = resolve(job.get('args', []), used, dependencies)
|
|
kwargs = resolve(job.get('kwargs', {}), used, dependencies)
|
|
require(isinstance(args, list) and isinstance(kwargs, dict), 'Structured producer arguments required')
|
|
source_names, native_names = job.get('source_inputs'), job.get('native_inputs')
|
|
require(isinstance(source_names, list) and source_names and isinstance(native_names, list) and native_names and
|
|
all(isinstance(n, str) and n in used for n in source_names + native_names),
|
|
'Actual pinned Source/native argument inputs required')
|
|
policy = job.get('override_policy')
|
|
require(policy in ('preserve-existing', 'qualified-same-identity'), 'Explicit row override policy required')
|
|
pins = job.get('old_rows', [])
|
|
require(isinstance(pins, list), 'Old row pin list required')
|
|
if can_override:
|
|
require(policy == 'qualified-same-identity' and pins, 'Existing-field producer requires qualified old-row pins')
|
|
if policy == 'qualified-same-identity':
|
|
require(pins, 'Qualified override requires old-row pins')
|
|
elif any(kwargs.get(k) is True for k in ('replace', 'replace_existing', 'replace_category',
|
|
'source_authoritative', 'source_authoritative_links', 'allow_on_hit_replacement')):
|
|
raise ValueError('Preserve policy cannot request an existing-row override')
|
|
for pin in pins:
|
|
require(isinstance(pin, dict) and pin.get('input') in native_names and 'sha256' in pin,
|
|
'Old row must be a declared native input')
|
|
if pin.get('encoding')=='input-bytes':
|
|
require(set(pin)=={'input','sha256','encoding'} and pin['sha256']==refs[pin['input']]['sha256'],
|
|
'Whole native-input pin must retain the declared exact byte identity')
|
|
# Argument resolution already read and verified this input.
|
|
# Pinning its full immutable bytes covers all old rows and
|
|
# avoids serializing a large package a second time.
|
|
document(pin['input'])
|
|
continue
|
|
require(pin.get('encoding')in(None,'canonical-json'),'Unsupported old-row pin encoding')
|
|
old = pointer(document(pin['input']), pin.get('pointer', ''))
|
|
require(digest(encoded(old)) == pin['sha256'], 'Pinned old row differs')
|
|
# Fixed functions retain their own exact field/domain/identity checks.
|
|
bound = inspect.signature(function).bind(*args, **kwargs)
|
|
signature = digest(encoded({'operation': operation, 'arguments': job.get('args', []),
|
|
'keywords': job.get('kwargs', {}), 'policy': policy, 'old_rows': pins,
|
|
'inputs': {n: refs[n]['sha256'] for n in sorted(used)},
|
|
'results': {n: digest(encoded(previous[n])) for n in sorted(dependencies)},
|
|
'contract': row['contract']}))
|
|
row['source_sha256'] = [refs[n]['sha256'] for n in source_names]
|
|
row['native_sha256'] = [refs[n]['sha256'] for n in native_names]
|
|
if action == 'plan':
|
|
row.update(status='PLANNED', scope='Fixed API route; existing producer qualification still pending')
|
|
# Planned dependent jobs cannot assume an uncomputed result.
|
|
results.append(row)
|
|
continue
|
|
if signature in refused:
|
|
row['conversion_reused'] = True
|
|
raise ValueError(refused[signature])
|
|
if signature not in converted:
|
|
try:
|
|
try:
|
|
value = function(*bound.args, **bound.kwargs)
|
|
body = encoded(value)
|
|
except item_catalog.NoOwnedMetadataPairs as no_change:
|
|
require(operation=='items.catalog-metadata-batch','Catalogue no-op belongs to its exact producer')
|
|
value={'package':bound.arguments['package'],'header':None,'selected':[],
|
|
'excluded':no_change.excluded,'added':[],'no_owned_delta':True}
|
|
# Reuse the exact native input instead of copying its
|
|
# 100 MiB package/header merely to record a no-op.
|
|
body=encoded({'kind':'classic-data-reused-native-base-v1','no_owned_delta':True,
|
|
'package_argument':job.get('args',[])[0],
|
|
'native_inputs':{n:refs[n]for n in native_names},
|
|
'selected':[],'excluded':no_change.excluded,'added':[]})
|
|
require(len(body) <= 128 * 1024 * 1024, 'Data candidate byte bound')
|
|
except (ValueError, TypeError, KeyError, IndexError, OSError, NotImplementedError) as error:
|
|
refused[signature] = str(error)
|
|
raise
|
|
sha256 = digest(body)
|
|
name = sha256 + '.data.json'
|
|
if not (target / name).exists():
|
|
(target / name).write_bytes(body)
|
|
converted[signature] = (value, {'file': name, 'sha256': sha256, 'bytes': len(body)})
|
|
else:
|
|
row['conversion_reused'] = True
|
|
value, row['output'] = converted[signature]
|
|
previous[job['id']] = value
|
|
previous_inputs[job['id']] = set(used)
|
|
row.update(status='STAGED', scope='Actual existing data producer output; offline candidate only',
|
|
acceptance=['Existing producer field/identity/serialization guards passed',
|
|
'Original native consumer and gameplay acceptance remain required'])
|
|
record_counts=item_result_denominators(operation,value)
|
|
if record_counts is not None:row['record_counts']=record_counts
|
|
if operation=='items.property-catalogue-assessment':
|
|
row.update(catalogue_counts=value['counts'],
|
|
scope='Catalogue assessment only; eligible records still require their existing producer and independent dependency checks',
|
|
acceptance=['Pinned Source/native inputs and existing catalogue join passed',
|
|
'No item metadata, spell semantics, installation or native gameplay is certified'])
|
|
if isinstance(value,dict)and value.get('no_owned_delta')is True:
|
|
reasons={}
|
|
for excluded in value['excluded']:
|
|
reason=excluded.get('reason','unknown');reasons[reason]=reasons.get(reason,0)+1
|
|
row.update(no_owned_delta=True,scope='Existing native base reused; no new qualified metadata pairs',
|
|
catalogue_counts={'selected':0,'excluded':len(value['excluded']),'excluded_reasons':reasons})
|
|
except (ValueError, TypeError, KeyError, IndexError, OSError, NotImplementedError) as error:
|
|
row.update(status='HELD', reason=str(error), error_type=type(error).__name__)
|
|
results.append(row)
|
|
cache.stable()
|
|
counts = {s: sum(r['status'] == s for r in results) for s in ('PLANNED', 'STAGED', 'HELD')}
|
|
report = {'kind': 'classic-data-batch-report-v1', 'action': action, 'manifest_sha256': digest(raw),
|
|
'requested': len(jobs), 'resolved': counts['STAGED'], 'held': counts['HELD'], 'counts': counts,
|
|
'rows': results, 'unique_input_files_read': len(cache.cache), 'input_bytes_read': cache.bytes_read,
|
|
'unique_producer_calls': len(converted) + len(refused), 'native_assets_preserved': True,
|
|
'candidate_content_complete': False, 'installed': False, 'native_verified': False,
|
|
'gameplay_verified': False,
|
|
'limits': ['Only existing fixed producer contracts are admitted.',
|
|
'Per-family blocked/excluded data remains in producer output.',
|
|
'No asset bodies, client files, live database or runtime state are modified.']}
|
|
if target is not None:
|
|
(target / 'report.json').write_bytes(encoded(report))
|
|
return report
|
|
|
|
|
|
def plan_batch(request, *, base_directory=None):
|
|
return run_batch(request, action='plan', base_directory=base_directory)
|
|
|
|
|
|
def convert_batch(request, output, *, base_directory=None):
|
|
return run_batch(request, action='convert', output=output, base_directory=base_directory)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--manifest', type=Path, required=True)
|
|
parser.add_argument('--action', choices=('plan', 'convert'), default='plan')
|
|
parser.add_argument('--output', type=Path)
|
|
args = parser.parse_args()
|
|
report = run_batch(args.manifest, action=args.action, output=args.output)
|
|
print(json.dumps({k: report[k] for k in ('requested', 'resolved', 'held', 'counts')}))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|