feat: approximate NVRAM requirement from the CAP analysis (v3.5.15)

GlobalPlatform models this explicitly (GP Card Spec v2.3.1 Table 11-48,
load parameters): C6 = non-volatile code, C7 = volatile data, C8 =
non-volatile data, and 11.5.2.3.7 - when the card makes no code/data
distinction the required minimum is C6 + C8.  The analysis now reports it:

- capmem.memory_json() accepts the load file size (all CAP components -
  the package image the card stores) and returns code.load_file,
  nvram.requirement = load_file + persistent data, and sets the suggested
  C6 to the load file (the bytecode-only Method.cap figure stays in
  code.method_component); _cap_info_body passes the size it already
  computed.
- The CAP estimate box (both the RAM installer and the SCP81
  Install-from-.cap form) leads with "NVRAM requirement ≈ code image +
  data" plus the RAM estimate, keeps the bytecode/other-component split and
  the full data breakdown in Details, and carries the GP citation with the
  caveats (card memory management, allocation rounding and the registry
  entry are not included; the static field image appears in both parts).
- An older server response without code.load_file still renders (the
  bytecode size is used as the fallback).

Tests: Python +1 (load-file semantics) with extended cap-info assertions,
frontend +1 (renderer + fallback).  Help EN/RU, docs/api.md, AGENTS.

587 frontend / 472 Python green; version 3.5.15; sw simple-v268.
This commit is contained in:
2026-09-27 02:14:49 +03:00
parent 2d2a40a73c
commit 18e0db75a9
10 changed files with 112 additions and 28 deletions
+20 -7
View File
@@ -48,10 +48,10 @@ function resetState() {
function memFixture() {
return {
code: { method_component: 2048 },
nvram: { static_image: 12, array_init: 4, install_objects: 100, header_overhead: 12, ref_storage: 8, total: 136, runtime: 0 },
code: { method_component: 2048, load_file: 3000 },
nvram: { static_image: 12, array_init: 4, install_objects: 100, header_overhead: 12, ref_storage: 8, total: 136, runtime: 0, requirement: 3136 },
ram: { transient_arrays: 16, runtime_transient: 0, peak_frame: 8, total: 24 },
suggested: { c6: 2048, c7: 272, c8: 136 },
suggested: { c6: 3000, c7: 272, c8: 136 },
warnings: [],
};
}
@@ -64,23 +64,36 @@ test('capMemBytes formats bytes and kilobytes', () => {
assert.strictEqual(capMemBytes(null), '0 B');
});
test('capMemHtml renders the summary, breakdown and warnings', () => {
test('capMemHtml renders the NVRAM requirement, breakdown and warnings', () => {
const mem = memFixture();
mem.warnings = ['method class[0].token[1]: unknown opcode 0xAA, scan stopped'];
const out = capMemHtml(mem);
assert.ok(out.includes('CAP requirements (estimate)'), out);
assert.ok(out.includes('Code (Method.cap): 2.0 kB'), out);
assert.ok(out.includes('Persistent (NVRAM): 136 B'), out);
// C6+C8-style total: load file + persistent data
assert.ok(out.includes('NVRAM requirement ≈ 3.1 kB (code image 2.9 kB + data 136 B)'), out);
assert.ok(out.includes('RAM (volatile): 24 B'), out);
assert.ok(out.includes('Code image (load file): 2.9 kB'), out);
assert.ok(out.includes('bytecode (Method.cap): 2.0 kB'), out);
assert.ok(out.includes('other components: 952 B'), out);
assert.ok(out.includes('Persistent data (NVRAM): 136 B'), out);
assert.ok(out.includes('Static image: 12 B'), out);
assert.ok(out.includes('Reference storage: 8 B'), out);
assert.ok(out.includes('Peak method frame: 8 B'), out);
assert.ok(out.includes('C6=2048 C7=0x0110 C8=0x0088'), out);
assert.ok(out.includes('C6=3000 C7=0x0110 C8=0x0088'), out);
assert.ok(out.includes('Table 11-48'), out);
assert.ok(out.includes('Estimate only'), out);
assert.ok(out.includes('unknown opcode 0xAA'), out);
assert.strictEqual(capMemHtml(null), '');
});
test('capMemHtml falls back to the bytecode size on older server responses', () => {
const mem = memFixture();
delete mem.code.load_file;
delete mem.nvram.requirement;
const out = capMemHtml(mem);
assert.ok(out.includes('NVRAM requirement ≈ 2.1 kB (code image 2.0 kB + data 136 B)'), out);
});
test('capGateOk gates the RAM install op and the scripts form', () => {
resetState();
globalThis.document = { getElementById: id => (id === 'ram-op' ? { value: 'install-cap' } : null) };