Skip to content

Conversation

@Mishael-2584
Copy link
Contributor

@Mishael-2584 Mishael-2584 commented Dec 5, 2025

Summary

Enhances the synk app-bundle upload command with comprehensive pre-upload validation, auto-activation capability, and improved user experience. This PR adds client-side validation that matches server-side logic, reducing unnecessary uploads and providing faster feedback to developers.

Changes

  • Pre-upload bundle validation - Validates structure, files, JSON syntax, and renderer references before upload
  • Auto-activation flag - --activate (or -a) flag to automatically activate uploaded version
  • Verbose output flag - --verbose (or -v) flag for detailed bundle information
  • Skip validation option - --skip-validation flag for edge cases (with warning)
  • Improved error messages - Color-coded output (green/yellow/red) for better visibility
  • Comprehensive test suite - 13 test cases covering all validation scenarios, all passing

Features Added

1. Validation Package (pkg/validation/bundle.go)

A new validation package that validates bundle structure before upload:

  • Structure Validation: Ensures only app/, forms/, renderers/ top-level directories exist
  • Required Files: Checks for app/index.html and required form files (forms/{formName}/schema.json, forms/{formName}/ui.json)
  • JSON Validation: Validates JSON syntax in all schema and UI files
  • Renderer References: Ensures all referenced renderers exist (either as custom renderers or built-in renderers)
  • Server Logic Match: Validation logic mirrors synkronus/pkg/appbundle/validation.go exactly

2. Enhanced Upload Command

The synk app-bundle upload command now includes:

  • Automatic validation by default (can be skipped with --skip-validation)
  • --activate flag to automatically activate the uploaded version
  • --verbose flag to show bundle statistics (size, file count, forms, renderers, manifest)
  • Color-coded output for better user experience

Testing

  • ✅ All 13 validation tests passing
  • ✅ Tested with real bundle files
  • ✅ Fresh build tested (no hardcoded paths)
  • ✅ Backward compatible (no breaking changes)

Test Coverage

The validation package includes comprehensive tests for:

  • Valid bundle structure
  • Missing required files (app/index.html, schema.json, ui.json)
  • Invalid top-level directories
  • Invalid form file paths
  • Invalid renderer structure
  • Missing renderer references
  • Invalid JSON syntax
  • Built-in renderer handling

Example Usage

Basic Upload (with automatic validation)

$ synk app-bundle upload bundle.zip
Validating bundle structure...
✓ Bundle structure is valid
Uploading bundle...
✓ App bundle uploaded successfully!
Version: 20250102-123456

Upload with Auto-Activation

$ synk app-bundle upload bundle.zip --activate
Validating bundle structure...
✓ Bundle structure is valid
Uploading bundle...
✓ App bundle uploaded successfully!
Version: 20250102-123456
Activating version 20250102-123456...
✓ Version 20250102-123456 activated successfully!

Upload with Verbose Output

$ synk app-bundle upload bundle.zip --verbose
Validating bundle structure...
✓ Bundle structure is valid

Bundle Information:
  Size: 245678 bytes
  Files: 15
  Forms: 3
  Renderers: 2

Uploading bundle...
✓ App bundle uploaded successfully!
Version: 20250102-123456

Manifest:
  Version: 20250102-123456
  Hash: abc123def456...
  Files: 15

Validation Error Handling

$ synk app-bundle upload invalid-bundle.zip
Validating bundle structure...
✗ Bundle validation failed: missing app/index.html

Files Changed

New Files

  • pkg/validation/bundle.go - Validation logic
  • pkg/validation/bundle_test.go - Test suite (13 test cases)

Modified Files

  • internal/cmd/appbundle.go - Enhanced upload command with validation and new flags
  • README.md - Updated documentation with new flags and examples
  • go.mod - Added github.com/fatih/color dependency
  • go.sum - Updated dependency checksums

Breaking Changes

None - fully backward compatible. The upload command works exactly as before, with validation enabled by default. Users can use --skip-validation if needed.

Related

Checklist

  • Code follows project style guidelines
  • Tests added/updated and passing
  • Documentation updated
  • No breaking changes
  • Ready for review

- Add comprehensive pre-upload validation matching server-side logic
- Add --activate flag for automatic version activation
- Add --verbose flag for detailed bundle information
- Add validation package with 13 comprehensive test cases
- Improve error messages with color-coded output
- Validate bundle structure, files, JSON, and renderer references

Closes #36
- Add forms/ prefix check before processing schema.json files
- Ensure path format is exactly forms/{formName}/schema.json
- Add test case to verify schema.json files outside forms/ are ignored
- Prevents incorrect validation of schema.json files in unexpected locations

Fixes issue where validator would process arbitrary schema.json files
outside the forms/ directory, causing incorrect validation behavior.
@Bahati308
Copy link
Contributor

This is awesome @Mishael-2584 , currently, we have to switch to a specific version with this synk app-bundle switch 00xx command, with the synk app-bundle upload bundle.zip --activate introduced, would it switch to the uploaded bundle automatically? And would it be possible to switch to any version still ?

@Mishael-2584
Copy link
Contributor Author

This is awesome @Mishael-2584 , currently, we have to switch to a specific version with this synk app-bundle switch 00xx command, with the synk app-bundle upload bundle.zip --activate introduced, would it switch to the uploaded bundle automatically? And would it be possible to switch to any version still ?

Yes to both questions that is the enhancement we are trying to make. @Bahati308 When you use synk app-bundle upload bundle.zip --activate, the CLI will:

  • Upload the bundle
  • Extract the version number from the response
  • Automatically call SwitchAppBundleVersion() internally to activate the newly uploaded version.

The synk app-bundle switch <version> command also remains fully functional and independent.

Copy link
Contributor

@r0ssing r0ssing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This is great!!
Later on we can discuss how to validate the json form against supported question/element types (i.e. we do not fully support all jsonforms possibilities)

@Mishael-2584 Mishael-2584 merged commit 5096974 into main Dec 8, 2025
7 checks passed
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.

4 participants