core

module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2025 License: MIT

README

specvital-core

Shared Go library for the specvital ecosystem.

Packages

Package Description
parser Test file parsing (20+ frameworks, tree-sitter)
crypto NaCl SecretBox encryption (shared by web & collector)
source Source abstraction (local filesystem, git repos)
domain Domain models (Inventory, TestFile, TestSuite)

Installation

go get github.com/specvital/core

Parser

Quick Start
package main

import (
    "context"
    "fmt"

    "github.com/specvital/core/pkg/parser"

    // Import frameworks to register them
    _ "github.com/specvital/core/pkg/parser/strategies/all" // All frameworks
)

func main() {
    ctx := context.Background()

    result, err := parser.Scan(ctx, "./my-project")
    if err != nil {
        panic(err)
    }

    fmt.Printf("Found %d test files with %d tests\n",
        len(result.Inventory.Files),
        result.Inventory.CountTests())
}
Scan Options
result, err := parser.Scan(ctx, rootPath,
    parser.WithWorkers(4),                    // Parallel workers (default: GOMAXPROCS)
    parser.WithTimeout(2*time.Minute),        // Scan timeout (default: 5 minutes)
    parser.WithExclude([]string{"fixtures"}), // Additional skip directories
    parser.WithScanPatterns([]string{"**/*.test.ts"}), // Glob patterns
)
Supported Frameworks
Language Frameworks
JavaScript/TS Jest, Vitest, Playwright, Cypress, Mocha
Go go testing
Python pytest, unittest
Java JUnit 5, TestNG
Kotlin Kotest
C# NUnit, xUnit, MSTest
Ruby RSpec, Minitest
PHP PHPUnit
Rust cargo test
C++ Google Test
Swift XCTest
Selective Import

Import only needed frameworks for smaller binaries:

import (
    _ "github.com/specvital/core/pkg/parser/strategies/jest"
    _ "github.com/specvital/core/pkg/parser/strategies/vitest"
    _ "github.com/specvital/core/pkg/parser/strategies/playwright"
)
Data Structures
type Inventory struct {
    RootPath string     // Scanned directory
    Files    []TestFile // Parsed test files
}

type TestFile struct {
    Path      string      // Relative file path
    Framework string      // "jest", "vitest", "playwright", "go", ...
    Language  Language    // "typescript", "javascript", "go", ...
    Suites    []TestSuite // Test suites (describe blocks)
    Tests     []Test      // Top-level tests
}

type TestSuite struct {
    Name     string      // Suite name
    Location Location    // Source location (line, column)
    Status   TestStatus  // "", "skipped", "only", ...
    Suites   []TestSuite // Nested suites
    Tests    []Test      // Tests in this suite
}

type Test struct {
    Name     string     // Test name
    Location Location   // Source location
    Status   TestStatus // "", "skipped", "only", "pending", "fixme"
}

Crypto

NaCl SecretBox encryption for sensitive data (OAuth tokens, etc.).

Quick Start
import "github.com/specvital/core/pkg/crypto"

// Create encryptor from Base64-encoded key
enc, err := crypto.NewEncryptorFromBase64(os.Getenv("ENCRYPTION_KEY"))
if err != nil {
    log.Fatal(err)
}
defer enc.Close()

// Encrypt
encrypted, err := enc.Encrypt(sensitiveData)

// Decrypt
decrypted, err := enc.Decrypt(encrypted)
Key Generation
openssl rand -base64 32
Security
  • XSalsa20 stream cipher (256-bit key)
  • Poly1305 MAC (integrity protection)
  • Random 192-bit nonce per encryption
  • Thread-safe for concurrent use

Source

Abstraction layer for reading files from different sources.

import "github.com/specvital/core/pkg/source"

// Local filesystem
src, err := source.NewLocalSource("./my-project")
defer src.Close()

// Git repository (clones to temp dir)
src, err := source.NewGitSource(ctx, "https://github.com/org/repo.git",
    source.WithRef("main"),
    source.WithDepth(1),
)
defer src.Close() // Cleans up temp directory

Development

# Unit tests
just test unit

# Integration tests (clones real GitHub repos, ~10min)
just test integration

# All tests
just test

# Update golden snapshots
just snapshot-update

License

MIT

Directories

Path Synopsis
pkg
crypto
Package crypto provides NaCl SecretBox encryption for secure data storage.
Package crypto provides NaCl SecretBox encryption for secure data storage.
domain
Package domain defines the core types for test file representation.
Package domain defines the core types for test file representation.
parser/framework
Package framework provides a unified framework definition system for test framework detection and parsing.
Package framework provides a unified framework definition system for test framework detection and parsing.
parser/framework/matchers
Package matchers provides reusable matcher implementations for framework detection.
Package matchers provides reusable matcher implementations for framework detection.
parser/strategies/all
Package all imports all parser strategies for side-effect registration.
Package all imports all parser strategies for side-effect registration.
parser/strategies/cargotest
Package cargotest implements Rust cargo test framework support.
Package cargotest implements Rust cargo test framework support.
parser/strategies/gtest
Package gtest implements Google Test framework support for C++ test files.
Package gtest implements Google Test framework support for C++ test files.
parser/strategies/junit5
Package junit5 implements JUnit 5 (Jupiter) test framework support for Java test files.
Package junit5 implements JUnit 5 (Jupiter) test framework support for Java test files.
parser/strategies/kotest
Package kotest implements Kotest test framework support for Kotlin test files.
Package kotest implements Kotest test framework support for Kotlin test files.
parser/strategies/minitest
Package minitest implements Minitest test framework support for Ruby test files.
Package minitest implements Minitest test framework support for Ruby test files.
parser/strategies/mstest
Package mstest implements MSTest framework support for C# test files.
Package mstest implements MSTest framework support for C# test files.
parser/strategies/nunit
Package nunit implements NUnit test framework support for C# test files.
Package nunit implements NUnit test framework support for C# test files.
parser/strategies/phpunit
Package phpunit implements PHPUnit test framework support for PHP test files.
Package phpunit implements PHPUnit test framework support for PHP test files.
parser/strategies/rspec
Package rspec implements RSpec test framework support for Ruby test files.
Package rspec implements RSpec test framework support for Ruby test files.
parser/strategies/shared/configutil
Package configutil provides shared utilities for parsing framework config files.
Package configutil provides shared utilities for parsing framework config files.
parser/strategies/shared/dotnetast
Package dotnetast provides shared C# AST traversal utilities for .NET test framework parsers.
Package dotnetast provides shared C# AST traversal utilities for .NET test framework parsers.
parser/strategies/shared/javaast
Package javaast provides shared Java AST traversal utilities for test framework parsers.
Package javaast provides shared Java AST traversal utilities for test framework parsers.
parser/strategies/shared/kotlinast
Package kotlinast provides shared Kotlin AST traversal utilities for test framework parsers.
Package kotlinast provides shared Kotlin AST traversal utilities for test framework parsers.
parser/strategies/shared/phpast
Package phpast provides shared PHP AST traversal utilities for test framework parsers.
Package phpast provides shared PHP AST traversal utilities for test framework parsers.
parser/strategies/shared/pyast
Package pyast provides shared Python AST traversal utilities for test framework parsers.
Package pyast provides shared Python AST traversal utilities for test framework parsers.
parser/strategies/shared/rubyast
Package rubyast provides utilities for working with Ruby AST nodes.
Package rubyast provides utilities for working with Ruby AST nodes.
parser/strategies/shared/swiftast
Package swiftast provides shared Swift AST traversal utilities for test framework parsers.
Package swiftast provides shared Swift AST traversal utilities for test framework parsers.
parser/strategies/testng
Package testng implements TestNG test framework support for Java test files.
Package testng implements TestNG test framework support for Java test files.
parser/strategies/xctest
Package xctest implements XCTest framework support for Swift test files.
Package xctest implements XCTest framework support for Swift test files.
parser/strategies/xunit
Package xunit implements xUnit test framework support for C# test files.
Package xunit implements xUnit test framework support for C# test files.
parser/tspool
Package tspool provides tree-sitter parsers for concurrent parsing.
Package tspool provides tree-sitter parsers for concurrent parsing.
source
Package source provides abstractions for reading files from various data sources.
Package source provides abstractions for reading files from various data sources.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL