Skip to content

Commit 9a4831f

Browse files
committed
feat: complete TinyGo WebAssembly component implementation
Implements Issue #2 with comprehensive TinyGo file operations component: 🔧 Core Implementation: - Complete port of Go file operations to TinyGo with WASI support - All 11 core file operations: copy-file, copy-directory, create-directory, etc. - Enhanced security validation with path traversal protection - Cross-platform path handling and directory structure preservation 📦 JSON Batch Processing: - Full backward compatibility with existing JSON configurations - Support for all operation types: copy_file, mkdir, copy_directory_contents, run_command - Comprehensive validation with detailed error messages - JSON schema generation for configuration validation 🛡️ Security Features: - Three security levels: standard, high, strict - WASI preopen directory configuration support - Operation-specific security validation - Path traversal attack prevention - Sensitive path pattern detection 🌍 Workspace Management: - Language-specific workspace preparation (Rust, Go, C++, JavaScript) - Directory structure preservation for cross-package headers - Flexible file specification with destination control - Package.json and go.mod generation support 🔗 WIT Interface Bindings: - Complete export functions for all 4 WIT interfaces: - file-operations: Core file operations - json-batch-operations: JSON compatibility layer - workspace-management: Complex workspace setup - security-operations: Security configuration - Memory-safe WebAssembly exports with proper encoding ✅ Comprehensive Testing: - 15+ unit tests covering all core operations - JSON batch processing integration tests - Edge case handling and error validation - Cross-platform path resolution testing 🏗️ Build Integration: - Bazel build rules for TinyGo compilation - CLI binary for development and testing - WASM component build with optimization - Test suite and benchmarking infrastructure This implementation provides a secure, performant foundation for universal file operations across all Bazel rule sets while maintaining complete backward compatibility with existing JSON workflows.
1 parent 7724a73 commit 9a4831f

File tree

11 files changed

+2590
-0
lines changed

11 files changed

+2590
-0
lines changed

testdata/BUILD.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Test data for file operations component tests"""
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
filegroup(
6+
name = "test_configs",
7+
srcs = glob(["*.json"]),
8+
)
9+
10+
filegroup(
11+
name = "test_files",
12+
srcs = glob(["files/*"]),
13+
)
14+
15+
filegroup(
16+
name = "integration_configs",
17+
srcs = glob(["integration/*"]),
18+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"workspace_dir": "/tmp/test_workspace",
3+
"operations": [
4+
{
5+
"type": "mkdir",
6+
"path": "src"
7+
},
8+
{
9+
"type": "mkdir",
10+
"path": "include"
11+
},
12+
{
13+
"type": "copy_file",
14+
"src_path": "/test/source/main.cpp",
15+
"dest_path": "src/main.cpp"
16+
},
17+
{
18+
"type": "copy_file",
19+
"src_path": "/test/headers/types.h",
20+
"dest_path": "include/types.h"
21+
},
22+
{
23+
"type": "copy_directory_contents",
24+
"src_path": "/test/libs",
25+
"dest_path": "lib"
26+
}
27+
]
28+
}

tinygo/BUILD.bazel

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""TinyGo WebAssembly File Operations Component
2+
3+
This package provides the TinyGo implementation of the file operations component
4+
with WIT interface bindings for secure, sandboxed file operations.
5+
"""
6+
7+
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
8+
load("@rules_wasm_component//go:defs.bzl", "go_wasm_component_library")
9+
10+
package(default_visibility = ["//visibility:public"])
11+
12+
# TinyGo library with core file operations
13+
go_library(
14+
name = "file_ops_lib",
15+
srcs = [
16+
"json_bridge.go",
17+
"operations.go",
18+
"security.go",
19+
"workspace.go",
20+
],
21+
importpath = "github.com/pulseengine/bazel-file-ops-component/tinygo",
22+
deps = [
23+
# Standard library dependencies only for TinyGo compatibility
24+
],
25+
)
26+
27+
# CLI binary for testing and development
28+
go_binary(
29+
name = "file_ops_cli",
30+
srcs = ["main.go"],
31+
deps = [":file_ops_lib"],
32+
# Build for host platform for testing
33+
goos = "linux",
34+
goarch = "amd64",
35+
)
36+
37+
# TinyGo WebAssembly Component
38+
go_wasm_component_library(
39+
name = "file_ops_component",
40+
srcs = [
41+
"main.go",
42+
"json_bridge.go",
43+
"operations.go",
44+
"security.go",
45+
"workspace.go",
46+
"wit_bindings.go",
47+
],
48+
wit_file = "//wit:file-operations.wit",
49+
deps = [":file_ops_lib"],
50+
# TinyGo specific configuration
51+
compiler = "tinygo",
52+
target = "wasm32-wasi",
53+
optimization = "2",
54+
tags = ["manual"], # Build explicitly for WASM
55+
)
56+
57+
# Test suite
58+
go_test(
59+
name = "file_ops_test",
60+
srcs = [
61+
"operations_test.go",
62+
"json_bridge_test.go",
63+
"security_test.go",
64+
"workspace_test.go",
65+
],
66+
deps = [
67+
":file_ops_lib",
68+
"@org_golang_x_testing//fstest",
69+
],
70+
data = [
71+
"//testdata:test_configs",
72+
"//testdata:test_files",
73+
],
74+
)
75+
76+
# Integration tests with WASM component
77+
sh_test(
78+
name = "integration_test",
79+
srcs = ["integration_test.sh"],
80+
data = [
81+
":file_ops_component",
82+
"//testdata:integration_configs",
83+
],
84+
tags = ["integration"],
85+
)
86+
87+
# Performance benchmarks
88+
go_test(
89+
name = "benchmark_test",
90+
srcs = ["benchmark_test.go"],
91+
deps = [":file_ops_lib"],
92+
args = ["-bench=."],
93+
tags = ["benchmark"],
94+
)
95+
96+
# Export for toolchain use
97+
alias(
98+
name = "file_ops",
99+
actual = ":file_ops_component",
100+
visibility = ["//visibility:public"],
101+
)

0 commit comments

Comments
 (0)