Skip to content

feat(cicero-core): compress .cta archives with DEFLATE#872

Open
yashhzd wants to merge 1 commit intoaccordproject:mainfrom
yashhzd:feat/compress-cta-archives
Open

feat(cicero-core): compress .cta archives with DEFLATE#872
yashhzd wants to merge 1 commit intoaccordproject:mainfrom
yashhzd:feat/compress-cta-archives

Conversation

@yashhzd
Copy link
Copy Markdown

@yashhzd yashhzd commented Mar 14, 2026

Summary

Fixes #678

.cta template archives are currently created with STORE (no compression), producing files roughly 2x larger than necessary. As noted by @jeromesimeon, JSZip defaults to STORE when no compression option is passed.

This PR enables DEFLATE compression in TemplateSaver.toArchive() and expands test coverage from 2 to 16 test cases.

Changes

1. Enable DEFLATE compression

// Before — no compression (STORE)
return zip.generateAsync({
    type: 'nodebuffer'
}).then(something => {
    return Promise.resolve(something).then(result => {
        return result;
    });
});

// After — DEFLATE level 6
return zip.generateAsync({
    type: 'nodebuffer',
    compression: 'DEFLATE',
    compressionOptions: {
        level: 6
    }
});

Level 6 provides a good balance between compression ratio and speed (level 9 is only marginally smaller but significantly slower).

2. Clean up redundant Promise wrapping

The previous code wrapped generateAsync's result in an unnecessary Promise.resolve().then() chain that just returned the value unchanged. Simplified to a direct return.

3. Remove unused archiver devDependency

The archiver package (v5.3.1) was declared in devDependencies but never imported or used anywhere in the codebase. Removed to reduce install size and maintenance burden.

4. Expand TemplateSaver test coverage (2 → 16 tests)

TemplateSaver previously had only 2 tests. This PR adds 14 new tests across 4 categories:

Compression tests (2):

Test What it validates
DEFLATE verification Archive files use DEFLATE compression (magic \x08\x00)
Size comparison Compressed archive is smaller than uncompressed equivalent

Archive structure tests (7):

Test What it validates
package.json Present with correct template name
model/ directory Contains model files
grammar template text/grammar.tem.md present and non-empty
sample text text/sample.md present
logic/ directory Directory entry exists in archive
request.json Present when metadata includes request data
README.md Present when metadata includes README
No signature signature.json absent when template is unsigned

Backward compatibility tests (3):

Test What it validates
Roundtrip load Compressed archive loads via Template.fromArchive() with matching identifier and model count
Uncompressed .cta Pre-existing STORE archives still load correctly
Content preservation Template grammar and sample text survive compress→decompress roundtrip

Logo test (1):

Test What it validates
Binary logo logo.png included as binary in archive

All 192 tests pass (including 16 TemplateSaver tests). 7 pre-existing pending tests (template signing) unaffected.

Backward Compatibility

This is not a breaking change. JSZip's loadAsync() transparently handles both STORE and DEFLATE archives. The test suite explicitly verifies that:

  1. New compressed archives load correctly via Template.fromArchive()
  2. Pre-existing uncompressed .cta files continue to load without error
  3. Template content (grammar, samples, models) survives the roundtrip

As @mttrbrts asked in the original issue — this is safe because the reading side (JSZip) auto-detects compression format.

Author Checklist

  • Code compiles and all 192 tests pass
  • 14 new tests added (2 → 16 total for TemplateSaver)
  • Backward compatibility verified with existing .cta archives
  • Unused dependency removed
  • Signed-off-by for DCO

…t coverage

Enable DEFLATE compression (level 6) in TemplateSaver.toArchive() for
.cta archive files. Previously archives used STORE (no compression),
producing files roughly 2x larger than necessary.

Changes:
- Set compression to DEFLATE in JSZip generateAsync() call
- Simplify async return by removing redundant Promise wrapping
- Remove unused archiver devDependency (never imported in codebase)
- Expand TemplateSaver test coverage from 2 to 16 test cases:
  compression verification, archive structure validation,
  backward compatibility with uncompressed archives, roundtrip
  content preservation, and template-with-logo handling

Backward compatibility: JSZip.loadAsync() transparently handles both
STORE and DEFLATE archives, so existing uncompressed .cta files
continue to load without any changes.

Closes accordproject#678

Signed-off-by: Yash Goel <yashgoel0810@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Should archive files be actually compressed?

1 participant