test: add source-built Hopper conformance fixtures

This commit is contained in:
morluto
2026-07-12 19:32:29 +08:00
parent 4f18e26ee5
commit d648bcd2e4
13 changed files with 465 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
# Source-built conformance fixtures
These sources are deliberately small semantic oracles for REA providers. Run
`npm run verify:fixtures` on macOS to compile them into the ignored
`build/conformance/` directory, emit a hash-and-toolchain manifest, and verify
their Mach-O symbols and strings with native command-line tools.
Only source files are versioned. Generated binaries, generated large-fixture
source, debug information, and manifests must remain under `build/`.
The C fixture fixes a known call chain and strings. The version pair fixes an
added symbol, changed string, and changed call relationship. The generated
large fixture contains 1,205 uniquely named functions and strings so provider
pagination can be checked at boundaries of 500, 1,000, and 1,205. Objective-C,
Swift, and N-API-like fixtures provide metadata-oriented inputs without package
or network dependencies.
+19
View File
@@ -0,0 +1,19 @@
#include <stdio.h>
volatile int rea_c_global = 7;
__attribute__((noinline, used)) int rea_leaf(int value) {
puts("REA_C_LEAF");
return value + rea_c_global;
}
__attribute__((noinline, used)) int rea_branch(int value) {
return value > 3 ? rea_leaf(value) : rea_leaf(-value);
}
__attribute__((noinline, used)) int rea_entry(void) {
puts("REA_C_ENTRY");
return rea_branch(5);
}
int main(void) { return rea_entry() == 12 ? 0 : 1; }
+17
View File
@@ -0,0 +1,17 @@
typedef void *napi_env;
typedef void *napi_value;
typedef napi_value (*napi_callback)(napi_env, void *);
extern int napi_create_function(napi_env, const char *, unsigned long,
napi_callback, void *, napi_value *);
extern int napi_set_named_property(napi_env, napi_value, const char *, napi_value);
static napi_value rea_probe(napi_env env, void *info) { return (napi_value)info; }
__attribute__((visibility("default"))) napi_value napi_register_module_v1(
napi_env env, napi_value exports) {
const char *names[] = {"reaProbeOne", "reaProbeTwo", "reaProbeThree"};
for (int i = 0; i < 3; i++) {
napi_value function = 0;
napi_create_function(env, names[i], 0, rea_probe, 0, &function);
napi_set_named_property(env, exports, names[i], function);
}
return exports;
}
+21
View File
@@ -0,0 +1,21 @@
#import <Foundation/Foundation.h>
@protocol REAWidgetDelegate <NSObject>
- (void)widgetDidFinish;
@end
@interface REAWidget : NSObject
@property(nonatomic, weak) id<REAWidgetDelegate> delegate;
- (BOOL)performAction:(NSString *)action error:(NSError **)error;
@end
@implementation REAWidget
- (BOOL)performAction:(NSString *)action error:(NSError **)error {
NSLog(@"REA_OBJC_ACTION:%@", action);
return action.length > 0;
}
@end
int main(void) {
@autoreleasepool {
Protocol *protocol = @protocol(REAWidgetDelegate);
NSLog(@"%@", NSStringFromProtocol(protocol));
return [[[REAWidget alloc] init] performAction:@"run" error:0] ? 0 : 1;
}
}
+11
View File
@@ -0,0 +1,11 @@
import Darwin
protocol REAProtocol { func execute() -> Int }
struct REARecord { let value: Int }
enum REAState { case ready, finished }
final class REAService: REAProtocol {
@inline(never) func execute() -> Int { print("REA_SWIFT_EXECUTE"); return 42 }
}
extension REARecord { @inline(never) func doubled() -> Int { value * 2 } }
let service = REAService()
exit(service.execute() == 42 ? 0 : 1)
+9
View File
@@ -0,0 +1,9 @@
#include <stdio.h>
__attribute__((noinline, used)) int rea_version_leaf(void) {
puts("REA_VERSION_ONE");
return 1;
}
__attribute__((noinline, used)) int rea_version_entry(void) {
return rea_version_leaf();
}
int main(void) { return rea_version_entry() == 1 ? 0 : 1; }
+10
View File
@@ -0,0 +1,10 @@
#include <stdio.h>
__attribute__((noinline, used)) int rea_version_leaf(void) {
puts("REA_VERSION_TWO");
return 2;
}
__attribute__((noinline, used)) int rea_added(void) { return 40; }
__attribute__((noinline, used)) int rea_version_entry(void) {
return rea_version_leaf() + rea_added();
}
int main(void) { return rea_version_entry() == 42 ? 0 : 1; }
+33
View File
@@ -0,0 +1,33 @@
import { describe, expect, it } from "vitest";
import {
generateLargeFixture,
LARGE_FIXTURE_COUNT,
sha256,
sourceDigest,
} from "../scripts/lib/conformance-fixtures.mjs";
describe("source-built conformance fixtures", () => {
it("generates a deterministic large pagination fixture", () => {
const first = generateLargeFixture();
const second = generateLargeFixture();
expect(first).toBe(second);
expect(first.match(/int rea_page_/gu)).toHaveLength(LARGE_FIXTURE_COUNT);
expect(first).toContain("rea_page_0000");
expect(first).toContain("rea_page_1204");
expect(() => generateLargeFixture(0)).toThrow(/positive integer/u);
});
it("hashes source manifests independently of input ordering", () => {
const left = [
{ path: "b.c", content: "b" },
{ path: "a.c", content: "a" },
];
const right = [...left].reverse();
expect(sourceDigest(left)).toBe(sourceDigest(right));
expect(sourceDigest(left)).toMatch(/^[0-9a-f]{64}$/u);
expect(sha256("fixture")).not.toBe(sha256("changed"));
});
});