From 9b8f7ef63603d2562f66c7485f11207cf19a6a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B5nis=20Ormisson?= Date: Tue, 1 Dec 2026 14:19:01 +0200 Subject: [PATCH 1/7] Apply conformance supplement 0.6 to the frontend and plans Request validation fails with request_schema_invalid, including input schemas whose names are equal case-insensitively and numeric value labels on string variables. Name matching uses the unconditional per-code-point lowercase mapping (no Final_Sigma). A * or COMMENT comment ends at a period followed by whitespace or the end of input. A command without its terminating period is a syntax error. A name may contain an inner period. The reserved words are never names or INTO targets. VAR LAB and VAL LAB are unsupported commands. FORMATS Fw means Fw.0. A replace recode whose target is not its source fails plan validation with target_already_exists. Run the Frontend 0.1, 0.2 and 0.3, Plan 0.1 and 0.2 and In-Place 0.1 supplement manifests. The 0.1 cases run under the 0.2 contract; the 0.1 boundary case is skipped because PHP does not claim Frontend 0.1. --- src/Frontend/Spss/Binding/SchemaState.php | 2 +- src/Frontend/Spss/Lexer.php | 13 +++- src/Frontend/Spss/Parser.php | 43 ++++++----- src/Frontend/Spss/Request/InputSchema.php | 23 +++++- src/Frontend/Spss/Request/InputVariable.php | 9 ++- .../Spss/Request/SpssFrontendRequest.php | 2 +- src/Frontend/Spss/Token.php | 9 +++ .../Execution/PlanPreflight.php | 2 +- src/Transformation/Plan/PlanCodec.php | 14 +++- .../Frontend/Spss/Binding/SchemaStateTest.php | 21 +++++ .../Spss/Conformance/SpssFrontend02Test.php | 47 ++++++++++- tests/Frontend/Spss/SpssCompilerTest.php | 2 +- tests/Frontend/Spss/SpssFrontend03Test.php | 2 +- .../OfficialInPlaceTransformation01Test.php | 77 +++++++++++++++++-- .../Conformance/ManifestInventoryTest.php | 11 +++ .../Conformance/TransformationPlan01Test.php | 3 + .../Conformance/TransformationPlan02Test.php | 3 + 17 files changed, 244 insertions(+), 39 deletions(-) diff --git a/src/Frontend/Spss/Binding/SchemaState.php b/src/Frontend/Spss/Binding/SchemaState.php index d7d7e1f..d571556 100644 --- a/src/Frontend/Spss/Binding/SchemaState.php +++ b/src/Frontend/Spss/Binding/SchemaState.php @@ -118,6 +118,6 @@ public function addNumeric(string $name): void private function key(string $name): string { - return mb_strtolower($name, 'UTF-8'); + return InputSchema::matchKey($name); } } diff --git a/src/Frontend/Spss/Lexer.php b/src/Frontend/Spss/Lexer.php index fc34556..62d60dc 100644 --- a/src/Frontend/Spss/Lexer.php +++ b/src/Frontend/Spss/Lexer.php @@ -112,6 +112,15 @@ public function tokenize(string $source, bool $officialV03 = false): array $start = $offset; while ($offset < $length) { $identifierCharacter = $this->characterAt($source, $offset, $line, $column); + // A period is part of a name only when another name character follows it. + if ( + $identifierCharacter === '.' + && $offset + 1 < $length + && $this->isIdentifierPart($this->characterAt($source, $offset + 1, $line, $column)) + ) { + $this->advance($identifierCharacter, $offset, $line, $column); + continue; + } if (!$this->isIdentifierPart($identifierCharacter)) { break; } @@ -184,7 +193,7 @@ private function comment(string $source, int &$offset, int &$line, int &$column, } else { $this->advance($character, $offset, $line, $column); } - if (!$block && $character === '.') { + if (!$block && $character === '.' && ($offset >= strlen($source) || ctype_space($source[$offset]))) { return; } } @@ -288,7 +297,7 @@ private function isIdentifierStart(string $character): bool private function isIdentifierPart(string $character): bool { - return preg_match('/\A[\p{L}\p{M}\p{N}]\z/uD', $character) === 1 || str_contains('_@#$', $character); + return preg_match('/\A[\p{L}\p{M}\p{Nd}]\z/uD', $character) === 1 || str_contains('_@#$', $character); } private function characterAt(string $source, int $offset, int $line, int $column): string diff --git a/src/Frontend/Spss/Parser.php b/src/Frontend/Spss/Parser.php index 1f54b38..86151e9 100644 --- a/src/Frontend/Spss/Parser.php +++ b/src/Frontend/Spss/Parser.php @@ -65,6 +65,9 @@ public function parseTokens(array $tokens, bool $officialV03 = false): Program while (!$this->check(TokenType::EndOfFile)) { $command = $this->current(); + if (!$this->terminatorAhead()) { + $this->fail($command, 'Every SPSS command must end with a period.'); + } if ($this->matchKeyword('RECODE')) { $statements[] = $this->recode($command); while ($this->officialV03 && $this->match(TokenType::Slash)) { @@ -85,12 +88,6 @@ public function parseTokens(array $tokens, bool $officialV03 = false): Program } elseif ($this->matchKeyword('VALUE')) { $this->consumeKeyword('LABELS', 'Expected LABELS after VALUE.'); $statements[] = $this->valueLabels($command); - } elseif ($this->matchKeyword('VAR')) { - $this->consumeKeyword('LAB', 'Expected LAB after VAR.'); - $statements[] = $this->variableLabels($command); - } elseif ($this->matchKeyword('VAL')) { - $this->consumeKeyword('LAB', 'Expected LAB after VAL.'); - $statements[] = $this->valueLabels($command); } elseif ($this->matchKeyword('EXECUTE')) { $statements[] = new ExecuteStatement($command->line, $command->span); } elseif ($this->matchKeyword('COMPUTE')) { @@ -254,7 +251,7 @@ private function expressionOperand(string $message): ExpressionOperand return new LiteralOperand($token->lexeme, $token->span); } if ($this->current()->isWord()) { - $token = $this->advance(); + $token = $this->consumeIdentifier($message); return new VariableOperand($token->lexeme, $token->span); } @@ -302,16 +299,10 @@ private function formats(Token $command): FormatsStatement do { [$variables, $spans] = $this->existingVariables('FORMATS requires variables and a format.', $this->officialV03); $this->consume(TokenType::LeftParenthesis, 'Expected ( before the format.'); - $familyAndWidth = $this->consumeIdentifier('Expected an F format such as F8.2.'); - if (preg_match('/\AF([1-9][0-9]*)\z/iD', $familyAndWidth->lexeme, $matches) !== 1) { - $this->fail($familyAndWidth, 'Only the numeric F format family is supported.', 'invalid_format'); - } - $decimalToken = $this->consume(TokenType::Number, 'F format requires . followed by decimals.'); - if ( - $familyAndWidth->span->endOffset !== $decimalToken->span->startOffset - || preg_match('/\A\.([0-9]+)\z/D', $decimalToken->lexeme, $decimalMatches) !== 1 - ) { - $this->fail($decimalToken, 'F format must use the Fwidth.decimals form.', 'invalid_format'); + // The lexer reads Fw.d as one name because a name may contain an inner period. + $format = $this->consumeIdentifier('Expected an F format such as F8.2.'); + if (preg_match('/\AF([1-9][0-9]*)(?:\.([0-9]+))?\z/iD', $format->lexeme, $matches) !== 1) { + $this->fail($format, 'Only the numeric F format family is supported.', 'invalid_format'); } $rightParenthesis = $this->consume(TokenType::RightParenthesis, 'Expected ) after the format.'); foreach ($variables as $index => $variable) { @@ -319,7 +310,7 @@ private function formats(Token $command): FormatsStatement $variable, 'F', (int) $matches[1], - (int) $decimalMatches[1], + (int) ($matches[2] ?? 0), $spans[$index], SourceSpan::cover($spans[$index], $rightParenthesis->span), ); @@ -547,7 +538,7 @@ private function existingVariables(string $message, bool $multiple = true, bool $spans[$index] = SourceSpan::cover($spans[$index], $last->span); $variables[$index] = new VariableRange($variables[$index], $last->lexeme, $spans[$index]); } else { - $variable = $this->advance(); + $variable = $this->consumeIdentifier($message); $variables[] = $variable->lexeme; $spans[] = $variable->span; } @@ -580,10 +571,24 @@ private function consumeIdentifier(string $message): Token if (!$this->current()->isWord()) { $this->fail($this->current(), $message); } + if ($this->current()->isReservedWord()) { + $this->fail($this->current(), sprintf('%s is a reserved word and cannot name a variable.', $this->current()->lexeme)); + } return $this->advance(); } + private function terminatorAhead(): bool + { + for ($index = $this->position; $index < count($this->tokens); ++$index) { + if ($this->tokens[$index]->type === TokenType::Terminator) { + return true; + } + } + + return false; + } + private function consumeKeyword(string $keyword, string $message): Token { if (!$this->current()->isKeyword($keyword)) { diff --git a/src/Frontend/Spss/Request/InputSchema.php b/src/Frontend/Spss/Request/InputSchema.php index c945af7..cad491e 100644 --- a/src/Frontend/Spss/Request/InputSchema.php +++ b/src/Frontend/Spss/Request/InputSchema.php @@ -18,15 +18,34 @@ public function __construct(array $variables) self::schema('$.input_schema.variables', 'Variables must be a non-empty ordered array.'); } $validated = []; - foreach ($variables as $variable) { + $keys = []; + foreach ($variables as $index => $variable) { if (!$variable instanceof InputVariable) { self::schema('$.input_schema.variables', 'Every schema variable must be an InputVariable.'); } + $key = self::matchKey($variable->name); + if (isset($keys[$key])) { + self::schema('$.input_schema.variables[' . $index . '].name', 'Variable names must differ case-insensitively.'); + } + $keys[$key] = true; $validated[] = $variable; } $this->variables = $validated; } + /** + * Case-insensitive name key: the unconditional per-code-point lowercase + * mapping. Mapping each code point alone keeps mb_strtolower's full + * mappings but never applies the context-sensitive Final_Sigma rule. + */ + public static function matchKey(string $name): string + { + return implode('', array_map( + static fn(string $character): string => mb_strtolower($character, 'UTF-8'), + mb_str_split($name, 1, 'UTF-8'), + )); + } + public static function fromArray(mixed $raw, string $path = '$.input_schema'): self { if (!is_array($raw) || array_is_list($raw)) { @@ -54,6 +73,6 @@ public static function fromArray(mixed $raw, string $path = '$.input_schema'): s private static function schema(string $path, string $message): never { - throw TransformationFailure::at('plan_schema_invalid', $path, $message); + throw TransformationFailure::at('request_schema_invalid', $path, $message); } } diff --git a/src/Frontend/Spss/Request/InputVariable.php b/src/Frontend/Spss/Request/InputVariable.php index 9ff6a27..c799be9 100644 --- a/src/Frontend/Spss/Request/InputVariable.php +++ b/src/Frontend/Spss/Request/InputVariable.php @@ -35,6 +35,13 @@ public function __construct( self::schema('$.input_schema.variables[].measurement_level', 'Invalid measurement level.'); } self::valueLabels($valueLabels, '$.input_schema.variables[].value_labels'); + if ($storageKind === 'string') { + foreach ($valueLabels as $label) { + if ($label['value']['type'] !== 'string') { + self::schema('$.input_schema.variables[].value_labels', 'A string variable cannot have a numeric value label.'); + } + } + } } public static function fromArray(mixed $raw, string $path): self @@ -208,6 +215,6 @@ private static function string(mixed $value, string $path): string private static function schema(string $path, string $message): never { - throw TransformationFailure::at('plan_schema_invalid', $path, $message); + throw TransformationFailure::at('request_schema_invalid', $path, $message); } } diff --git a/src/Frontend/Spss/Request/SpssFrontendRequest.php b/src/Frontend/Spss/Request/SpssFrontendRequest.php index a186494..75faa77 100644 --- a/src/Frontend/Spss/Request/SpssFrontendRequest.php +++ b/src/Frontend/Spss/Request/SpssFrontendRequest.php @@ -80,6 +80,6 @@ private static function string(mixed $value, string $path): string private static function schema(string $path, string $message): never { - throw TransformationFailure::at('plan_schema_invalid', $path, $message); + throw TransformationFailure::at('request_schema_invalid', $path, $message); } } diff --git a/src/Frontend/Spss/Token.php b/src/Frontend/Spss/Token.php index cc3711a..f8b7728 100644 --- a/src/Frontend/Spss/Token.php +++ b/src/Frontend/Spss/Token.php @@ -35,6 +35,15 @@ public function isKeyword(string $keyword): bool return $this->isWord() && strcasecmp($this->lexeme, $keyword) === 0; } + public function isReservedWord(): bool + { + return $this->isWord() && in_array( + strtoupper($this->lexeme), + ['AND', 'OR', 'NOT', 'TO', 'EQ', 'NE', 'LT', 'LE', 'GT', 'GE', 'BY', 'ALL', 'WITH'], + true, + ); + } + public function isWord(): bool { return in_array($this->type, [ diff --git a/src/Transformation/Execution/PlanPreflight.php b/src/Transformation/Execution/PlanPreflight.php index 083b0f4..42039d0 100644 --- a/src/Transformation/Execution/PlanPreflight.php +++ b/src/Transformation/Execution/PlanPreflight.php @@ -276,7 +276,7 @@ private function bindRecodeTarget( } if ($existing->variableId !== $source->variableId) { throw TransformationFailure::at( - 'type_mismatch', + 'target_already_exists', $path . '.target', 'Recode replace requires source and target to identify the same variable.', ); diff --git a/src/Transformation/Plan/PlanCodec.php b/src/Transformation/Plan/PlanCodec.php index c8f56aa..b16c455 100644 --- a/src/Transformation/Plan/PlanCodec.php +++ b/src/Transformation/Plan/PlanCodec.php @@ -273,9 +273,19 @@ private function recodeOperation(array $object, string $path): RecodeOperation $rules[] = $this->rule($rawRule, $path . '.rules[' . $index . ']'); } + $source = $this->nonEmptyString($object['source'], $path . '.source'); + $target = $this->targetName($object['target'], $path . '.target'); + if ($targetMode === TargetMode::Replace && $target !== $source) { + throw TransformationFailure::at( + 'target_already_exists', + $path . '.target', + 'A replace recode must name its source as its target.', + ); + } + return new RecodeOperation( - $this->nonEmptyString($object['source'], $path . '.source'), - $this->targetName($object['target'], $path . '.target'), + $source, + $target, $targetMode, $rules, $this->result($object['unmatched'], $path . '.unmatched'), diff --git a/tests/Frontend/Spss/Binding/SchemaStateTest.php b/tests/Frontend/Spss/Binding/SchemaStateTest.php index 9bdbe91..7e6c65c 100644 --- a/tests/Frontend/Spss/Binding/SchemaStateTest.php +++ b/tests/Frontend/Spss/Binding/SchemaStateTest.php @@ -8,6 +8,7 @@ use OpenStatSpec\Frontend\Spss\Request\InputSchema; use OpenStatSpec\Frontend\Spss\Request\InputVariable; use OpenStatSpec\Transformation\Diagnostic\SourceSpan; +use OpenStatSpec\Transformation\Diagnostic\TransformationFailure; use PHPUnit\Framework\TestCase; final class SchemaStateTest extends TestCase @@ -20,4 +21,24 @@ public function testUnicodeVariableNamesResolveCaseInsensitively(): void self::assertSame($variable, $schema->resolve('ärger', new SourceSpan(0, 5))); self::assertTrue($schema->contains('ÄRGER')); } + + public function testNameMatchingUsesUnconditionalLowercaseWithoutFinalSigma(): void + { + $variable = new InputVariable('σασ', 'numeric'); + $schema = new SchemaState(new InputSchema([$variable])); + + self::assertSame($variable, $schema->resolve('ΣΑΣ', new SourceSpan(0, 6))); + self::assertSame("i\u{307}", InputSchema::matchKey('İ')); + self::assertFalse($schema->contains('ΣΑς')); + } + + public function testCaseInsensitiveDuplicateNamesAreRequestSchemaInvalid(): void + { + try { + new InputSchema([new InputVariable('σασ', 'numeric'), new InputVariable('ΣΑΣ', 'numeric')]); + self::fail('Duplicate names were accepted.'); + } catch (TransformationFailure $failure) { + self::assertSame('request_schema_invalid', $failure->diagnosticCode()); + } + } } diff --git a/tests/Frontend/Spss/Conformance/SpssFrontend02Test.php b/tests/Frontend/Spss/Conformance/SpssFrontend02Test.php index d75765c..8734a8f 100644 --- a/tests/Frontend/Spss/Conformance/SpssFrontend02Test.php +++ b/tests/Frontend/Spss/Conformance/SpssFrontend02Test.php @@ -20,14 +20,20 @@ public function testOfficialFrontend02Case(array $case): void { /** @var array $requestPayload */ $requestPayload = $case['request']; - $request = SpssFrontendRequest::fromArray($requestPayload); - self::assertSame($case['expected_source_hash'], $request->sourceHash(), (string) $case['id']); + self::assertSame( + $case['expected_source_hash'], + hash('sha256', str_replace(["\r\n", "\r"], "\n", (string) $requestPayload['source_text'])), + (string) $case['id'], + ); try { + $request = SpssFrontendRequest::fromArray($requestPayload); $result = (new SpssCompiler())->compile($request); } catch (TransformationFailure $failure) { self::assertSame($case['expected_error'], $failure->diagnosticCode(), (string) $case['id']); - self::assertNotNull($failure->diagnostics[0]->span, (string) $case['id']); + if ($failure->diagnosticCode() !== 'request_schema_invalid') { + self::assertNotNull($failure->diagnostics[0]->span, (string) $case['id']); + } return; } @@ -67,6 +73,41 @@ public function testOfficialFrontend03Case(array $case): void $this->testOfficialFrontend02Case($case); } + /** @param array $case */ + #[DataProvider('supplementCases')] + public function testSupplementCase(array $case): void + { + if ($case['id'] === '0.1/reject-frontend-0.2-command') { + self::markTestSkipped('PHP does not claim the Frontend 0.1 contract; under 0.2 and 0.3 COMPUTE is a supported command.'); + } + $this->testOfficialFrontend02Case($case); + } + + /** + * Supplement 1 of specification v0.6.0. The 0.1 cases run under the 0.2 + * contract, as the published 0.1 cases do when the 0.3 manifest inherits them. + * + * @return iterable}> + */ + public static function supplementCases(): iterable + { + foreach (['0.1', '0.2', '0.3'] as $version) { + $manifest = SpecificationManifest::load('conformance/spss-syntax-frontend-' . $version . '-supplement-1.json'); + foreach ($manifest['cases'] as $case) { + if ($version === '0.1') { + $case['request']['contract'] = SpssFrontendRequest::CONTRACT; + } + $case['id'] = $version . '/' . $case['id']; + yield $case['id'] => [$case]; + } + } + } + + public function testSupplementManifestCoverage(): void + { + self::assertCount(43, iterator_to_array(self::supplementCases())); + } + public function testOfficial03ManifestCoverage(): void { self::assertCount(35, SpecificationManifest::load('conformance/spss-syntax-frontend-0.3.json')['cases']); diff --git a/tests/Frontend/Spss/SpssCompilerTest.php b/tests/Frontend/Spss/SpssCompilerTest.php index 9c80475..2da2d98 100644 --- a/tests/Frontend/Spss/SpssCompilerTest.php +++ b/tests/Frontend/Spss/SpssCompilerTest.php @@ -67,7 +67,7 @@ public function testRequestRejectsEveryNonSchemaShape(array $payload, string $pa SpssFrontendRequest::fromArray($payload); self::fail('An invalid frontend request unexpectedly passed validation.'); } catch (TransformationFailure $failure) { - self::assertSame('plan_schema_invalid', $failure->diagnosticCode()); + self::assertSame('request_schema_invalid', $failure->diagnosticCode()); self::assertSame($path, $failure->diagnostics[0]->path); } } diff --git a/tests/Frontend/Spss/SpssFrontend03Test.php b/tests/Frontend/Spss/SpssFrontend03Test.php index 686efa0..83db7f7 100644 --- a/tests/Frontend/Spss/SpssFrontend03Test.php +++ b/tests/Frontend/Spss/SpssFrontend03Test.php @@ -20,7 +20,7 @@ public function testProductionRequestBoundaryRejectsInvalidShapes(array $payload (new SpssCompiler())->compile(SpssFrontendRequest::fromArray($payload)); self::fail('Invalid request compiled.'); } catch (TransformationFailure $failure) { - self::assertSame('plan_schema_invalid', $failure->diagnosticCode()); + self::assertSame('request_schema_invalid', $failure->diagnosticCode()); } } diff --git a/tests/Integration/OfficialInPlaceTransformation01Test.php b/tests/Integration/OfficialInPlaceTransformation01Test.php index 7c4edf6..bf7bf58 100644 --- a/tests/Integration/OfficialInPlaceTransformation01Test.php +++ b/tests/Integration/OfficialInPlaceTransformation01Test.php @@ -215,7 +215,74 @@ public function testOptInFrontend03AppliesNativelyWithProvenanceAndNoExtraDataAr self::assertFalse($pdo->inTransaction()); } - private function fixture(): PDO + /** @param array $case */ + #[DataProvider('supplementCases')] + public function testSupplementCase(array $case): void + { + self::assertSame('sqlite', $case['database_profile']); + $before = $case['before']; + $after = $case['after']; + $pdo = $this->fixture((string) $before['dataset_id'], (string) $before['physical_table_name']); + $tablesBefore = $this->tables($pdo); + $datasetBefore = $this->rows($pdo, 'SELECT * FROM dataset'); + self::assertSame($before['physical_table_schema'], $datasetBefore[0]['physical_table_schema']); + self::assertSame($before['dataset_count'], count($datasetBefore)); + self::assertSame($before['persistent_data_table_count'], count($this->dataTables($pdo))); + + $compiled = (new SpssCompiler())->compile(SpssFrontendRequest::fromArray([ + 'contract' => SpssFrontendRequest::CONTRACT, + 'input_alias' => 'parent', + 'input_schema' => ['variables' => [['name' => 'q1', 'storage_kind' => 'numeric']]], + 'source_text' => (string) $case['source_text'], + ])); + (new InPlaceTransformationExecutor(new Connection($pdo)))->execute(new InPlaceApplyRequest( + $compiled->plan, + 'parent', + (string) $before['dataset_id'], + $compiled->sourceHash, + 'conformance-runner', + )); + + $dataset = $this->rows($pdo, 'SELECT * FROM dataset'); + self::assertCount($after['dataset_count'], $dataset); + self::assertSame($after['dataset_id'], $dataset[0]['dataset_id']); + self::assertSame($after['physical_table_schema'], $dataset[0]['physical_table_schema']); + self::assertSame($after['physical_table_name'], $dataset[0]['physical_table_name']); + self::assertSame($tablesBefore, $this->tables($pdo), 'forbidden artifacts'); + self::assertSame([], $this->rows($pdo, "SELECT name FROM sqlite_temp_master WHERE type = 'table'")); + self::assertSame($after['persistent_data_table_count'], count($this->dataTables($pdo))); + $target = $this->rows($pdo, 'SELECT physical_name, storage_kind FROM variable WHERE source_name = ?', [$after['created_target']]); + self::assertCount(1, $target); + self::assertSame($after['created_target_storage_kind'], $target[0]['storage_kind']); + self::assertTrue($after['created_target_all_system_missing']); + self::assertSame([null, null, null, null, null, null, null], $this->column( + $pdo, + 'SELECT "' . $target[0]['physical_name'] . '" FROM "' . $after['physical_table_name'] . '" ORDER BY __case_ordinal', + )); + $audit = $this->rows($pdo, 'SELECT * FROM transformation_apply'); + self::assertCount(1, $audit); + foreach ($case['required_audit_fields'] as $field) { + self::assertArrayHasKey($field, $audit[0]); + } + self::assertSame($after['audit_physical_table_schema'], $audit[0]['physical_table_schema']); + self::assertSame('succeeded', $audit[0]['status']); + } + + /** @return iterable}> */ + public static function supplementCases(): iterable + { + foreach (SpecificationManifest::load('conformance/in-place-transformation-0.1-supplement-1.json')['cases'] as $case) { + yield $case['id'] => [$case]; + } + } + + /** @return list */ + private function dataTables(PDO $pdo): array + { + return array_map('strval', $this->column($pdo, 'SELECT physical_table_name FROM dataset')); + } + + private function fixture(string $datasetId = self::DATASET_ID, string $table = 'data_plan01'): PDO { if (!in_array('sqlite', PDO::getAvailableDrivers(), true)) { self::markTestSkipped('PDO SQLite is not available.'); @@ -225,14 +292,14 @@ private function fixture(): PDO (new NormativeCatalog($pdo))->createTables(); (new TransformationAuditMigrator($pdo))->migrate(); CatalogOwnership::markCurrentVersion($pdo); - $pdo->exec('CREATE TABLE data_plan01 (__case_ordinal INTEGER NOT NULL PRIMARY KEY, q1 REAL NULL)'); + $pdo->exec('CREATE TABLE ' . $table . ' (__case_ordinal INTEGER NOT NULL PRIMARY KEY, q1 REAL NULL)'); $pdo->prepare( 'INSERT INTO dataset (dataset_id, spec_version, source_format, physical_table_schema, physical_table_name, dataset_name, source_case_count, imported_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', - )->execute([self::DATASET_ID, '1.0', 'fixture', null, 'data_plan01', 'Plan 0.1 fixture', 7, '2026-08-17 00:00:00']); + )->execute([$datasetId, '1.0', 'fixture', null, $table, 'Plan 0.1 fixture', 7, '2026-08-17 00:00:00']); $pdo->prepare( 'INSERT INTO variable (variable_id, dataset_id, source_ordinal, source_name, physical_name, storage_kind) VALUES (?, ?, ?, ?, ?, ?)', - )->execute(['88888888-8888-4888-8888-888888888888', self::DATASET_ID, 1, 'q1', 'q1', 'numeric']); - $insert = $pdo->prepare('INSERT INTO data_plan01 (__case_ordinal, q1) VALUES (?, ?)'); + )->execute(['88888888-8888-4888-8888-888888888888', $datasetId, 1, 'q1', 'q1', 'numeric']); + $insert = $pdo->prepare('INSERT INTO ' . $table . ' (__case_ordinal, q1) VALUES (?, ?)'); foreach ([[1, 1.0], [2, 2.0], [3, 3.0], [4, 4.0], [5, 5.0], [6, 6.0], [7, null]] as $row) { $insert->execute($row); } diff --git a/tests/Transformation/Conformance/ManifestInventoryTest.php b/tests/Transformation/Conformance/ManifestInventoryTest.php index d6b8b5a..ae12303 100644 --- a/tests/Transformation/Conformance/ManifestInventoryTest.php +++ b/tests/Transformation/Conformance/ManifestInventoryTest.php @@ -17,4 +17,15 @@ public function testPinnedTransformationManifestInventory(): void self::assertCount(6, SpecificationManifest::load('conformance/in-place-transformation-0.1.json')['cases']); self::assertCount(11, SpecificationManifest::load('conformance/in-place-transformation-0.2.json')['cases']); } + + public function testPinnedSupplementManifestInventory(): void + { + self::assertCount(15, SpecificationManifest::load('conformance/spss-syntax-frontend-0.1-supplement-1.json')['cases']); + self::assertCount(14, SpecificationManifest::load('conformance/spss-syntax-frontend-0.2-supplement-1.json')['cases']); + self::assertCount(14, SpecificationManifest::load('conformance/spss-syntax-frontend-0.3-supplement-1.json')['cases']); + self::assertCount(2, SpecificationManifest::load('conformance/transformation-plan-0.1-supplement-1.json')['cases']); + self::assertCount(2, SpecificationManifest::load('conformance/transformation-plan-0.2-supplement-1.json')['cases']); + self::assertCount(1, SpecificationManifest::load('conformance/in-place-transformation-0.1-supplement-1.json')['cases']); + self::assertCount(9, SpecificationManifest::load('conformance/spss-sav-zsav-1.0-supplement-1.json')['fixtures']); + } } diff --git a/tests/Transformation/Conformance/TransformationPlan01Test.php b/tests/Transformation/Conformance/TransformationPlan01Test.php index 3c52a52..06c4d47 100644 --- a/tests/Transformation/Conformance/TransformationPlan01Test.php +++ b/tests/Transformation/Conformance/TransformationPlan01Test.php @@ -152,6 +152,9 @@ public static function cases(): iterable foreach (SpecificationManifest::load('conformance/transformation-plan-0.1.json')['cases'] as $case) { yield $case['id'] => [$case]; } + foreach (SpecificationManifest::load('conformance/transformation-plan-0.1-supplement-1.json')['cases'] as $case) { + yield 'supplement-1/' . $case['id'] => [$case]; + } } /** @param array $case */ diff --git a/tests/Transformation/Conformance/TransformationPlan02Test.php b/tests/Transformation/Conformance/TransformationPlan02Test.php index 077ddf2..a06a4dd 100644 --- a/tests/Transformation/Conformance/TransformationPlan02Test.php +++ b/tests/Transformation/Conformance/TransformationPlan02Test.php @@ -39,6 +39,9 @@ public static function cases(): iterable foreach (SpecificationManifest::load('conformance/transformation-plan-0.2.json')['cases'] as $case) { yield $case['id'] => [$case]; } + foreach (SpecificationManifest::load('conformance/transformation-plan-0.2-supplement-1.json')['cases'] as $case) { + yield 'supplement-1/' . $case['id'] => [$case]; + } } /** @param array $case */ From ada8f4fc536a45e41b1d611586c62f16122a02f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B5nis=20Ormisson?= Date: Tue, 1 Dec 2026 14:27:59 +0200 Subject: [PATCH 2/7] Store catalogue vocabularies as text and refuse negative zero Write measurement_level, variable_role and display_alignment as the text vocabularies of Conformance Supplement 0.6; an unknown measurement level is NULL. The exporter also reads the numeric codes of earlier releases, and migrateCatalog() rewrites them as text. catalog_identity.schema_version is 1, the schema outline version. The private migration counter stays in openstatspec_schema_migration and moves to 5, recorded by markCurrentVersion() after every step. A catalogue completed by 0.8.x (identity 4, marker 4) stays ready. Refuse negative zero before mutation in the shared import preflight and in MySQL-family dictionary values, and declare the refusal for Dolt. Export attributes by name in code-point order on every server. Run the SAV/ZSAV 1.0 supplement manifest, generating the negative-zero and NaN fixtures, and compare round-trip attributes by name. --- src/Core/CapabilityDeclaration.php | 1 + src/Spss/SpssAdapter.php | 1 + src/Sql/AbstractPdoSqlProfile.php | 7 + src/Sql/CanonicalWideTableExporter.php | 32 ++- src/Sql/CatalogOwnership.php | 52 +++-- src/Sql/MySqlWideTableImporter.php | 6 + src/Sql/NormativeCatalog.php | 43 +++- tests/Core/CapabilityDeclarationTest.php | 1 + .../OfficialSpssConformanceManifestTest.php | 198 ++++++++++++++++-- tests/Spss/SpssAdapterTest.php | 48 ++++- tests/Sql/CatalogOwnershipTest.php | 4 +- .../Audit/TransformationAuditMigratorTest.php | 6 +- 12 files changed, 345 insertions(+), 54 deletions(-) diff --git a/src/Core/CapabilityDeclaration.php b/src/Core/CapabilityDeclaration.php index f0e8fd8..825cf05 100644 --- a/src/Core/CapabilityDeclaration.php +++ b/src/Core/CapabilityDeclaration.php @@ -193,6 +193,7 @@ private function profile(string $name, PdoSqlProfile $profile, bool $active): ar 'nan' => 'reject_before_mutation', 'positive_infinity' => 'reject_before_mutation', 'negative_infinity' => 'reject_before_mutation', + 'negative_zero' => 'reject_before_mutation', 'system_missing' => 'sql_null', ] : null, 'storage_evidence' => $name === 'dolt' ? [ diff --git a/src/Spss/SpssAdapter.php b/src/Spss/SpssAdapter.php index e433079..056163d 100644 --- a/src/Spss/SpssAdapter.php +++ b/src/Spss/SpssAdapter.php @@ -70,6 +70,7 @@ public function migrateCatalog(): void $catalog->createTables(); (new TransformationAuditMigrator($this->connection->pdo))->migrate(); $this->backfillLegacyDatasets($catalog); + $catalog->migrateVocabularies(); CatalogOwnership::markCurrentVersion($this->connection->pdo); } diff --git a/src/Sql/AbstractPdoSqlProfile.php b/src/Sql/AbstractPdoSqlProfile.php index 43d2d63..b2b5fd7 100644 --- a/src/Sql/AbstractPdoSqlProfile.php +++ b/src/Sql/AbstractPdoSqlProfile.php @@ -121,6 +121,13 @@ public function assertDataset(array $variables, array $rows, ?PDO $pdo = null): $this->driverName() . ' rejects non-finite SPSS numeric values before mutation.', ); } + // The PDO profiles store negative zero as positive zero; a silent change is not conformant. + if ($value === 0.0 && fdiv(1.0, $value) < 0) { + throw new UnsupportedOperation( + DiagnosticCode::TargetCapabilityExceeded, + $this->driverName() . ' rejects negative-zero SPSS numeric values before mutation.', + ); + } } elseif ($value !== null && !is_int($value)) { $this->invalidNumericValue(); } diff --git a/src/Sql/CanonicalWideTableExporter.php b/src/Sql/CanonicalWideTableExporter.php index 23eebf3..949286e 100644 --- a/src/Sql/CanonicalWideTableExporter.php +++ b/src/Sql/CanonicalWideTableExporter.php @@ -81,15 +81,10 @@ public function export(string $datasetName, string $targetFormat = 'sav'): array label: $variable['variable_label'] === null ? null : $this->text($variable['variable_label']), valueLabels: new ValueLabelSet($labels, [$name]), missingValues: $this->missingValues($missingByVariable[$variableId] ?? []), - measure: match ($variable['measurement_level']) { - 'nominal' => Measure::NOMINAL, - 'ordinal' => Measure::ORDINAL, - 'scale' => Measure::SCALE, - default => Measure::tryFrom($this->integer($variable['measurement_level'] ?? 0)) ?? Measure::UNKNOWN, - }, - alignment: Alignment::tryFrom($this->integer($variable['display_alignment'] ?? 0)) ?? Alignment::LEFT, + measure: Measure::from($this->vocabularyCode($variable['measurement_level'], [0 => 'unknown'] + NormativeCatalog::MEASUREMENT_LEVELS) ?? 0), + alignment: Alignment::from($this->vocabularyCode($variable['display_alignment'], NormativeCatalog::DISPLAY_ALIGNMENTS) ?? 0), columns: max(0, $this->integer($variable['display_width'] ?? 8)), - role: VariableRole::tryFrom($this->integer($variable['variable_role'] ?? 0)) ?? throw $this->invalid('Invalid variable role.'), + role: VariableRole::from($this->vocabularyCode($variable['variable_role'], NormativeCatalog::VARIABLE_ROLES) ?? 0), attributes: $attributes, dictionaryIndex: $this->integer($variable['source_ordinal']), ); @@ -253,6 +248,8 @@ private function attributes(array $rows): array foreach ($rows as $row) { $attributes[$this->string($row['attribute_name'])][] = $this->text($row['attribute_value']); } + // Export order is by name in code-point order, whatever the server collation. + ksort($attributes, SORT_STRING); return $attributes; } @@ -281,6 +278,25 @@ private function integer(mixed $value): int return (int) $value; } + /** + * Accept the text vocabulary and the legacy numeric strings of earlier releases. + * + * @param array $values + */ + private function vocabularyCode(mixed $value, array $values): ?int + { + if ($value === null) { + return null; + } + $code = is_int($value) || (is_string($value) && ctype_digit($value)) + ? (int) $value + : array_search($value, $values, true); + if (!is_int($code) || !array_key_exists($code, $values)) { + throw $this->invalid('Invalid variable vocabulary value.'); + } + return $code; + } + private function text(mixed $value): string { if (!is_string($value)) { diff --git a/src/Sql/CatalogOwnership.php b/src/Sql/CatalogOwnership.php index 0ec7ad3..e3c4cba 100644 --- a/src/Sql/CatalogOwnership.php +++ b/src/Sql/CatalogOwnership.php @@ -16,7 +16,13 @@ final class CatalogOwnership private const CONTRACT_ID = 'openstatspec-strict-wide-table-v1'; private const MIGRATION_TABLE = 'openstatspec_schema_migration'; private const AUDIT_TABLE = 'transformation_apply'; - private const SCHEMA_VERSION = 4; + /** catalog_identity.schema_version: the version of the specification's sql/schema-outline.sql. */ + private const IDENTITY_SCHEMA_VERSION = 1; + /** Releases before 0.9.0 stored their private migration counter (1..4) in catalog_identity. */ + private const LEGACY_IDENTITY_MAXIMUM = 4; + /** Private migration counter, recorded in openstatspec_schema_migration only. */ + private const SCHEMA_VERSION = 5; + private const AUDIT_MIGRATION_VERSION = 4; /** @return array */ public static function binding(PDO $pdo): array @@ -64,18 +70,18 @@ public static function ensure(PDO $pdo): void ); } self::assertExclusiveNamespace($pdo); - self::createIdentity($pdo, $markerVersion); + self::createIdentity($pdo); return; } if (self::isRecognizedFullLegacyCatalog($pdo, $collisions)) { self::assertExclusiveNamespace($pdo); - self::createIdentity($pdo, 1); + self::createIdentity($pdo); $pdo->exec('CREATE TABLE ' . self::MIGRATION_TABLE . ' (version INTEGER NOT NULL PRIMARY KEY, applied_at TIMESTAMP NOT NULL)'); return; } if (self::isRecognizedJournalOnlyLegacyCatalog($pdo, $collisions)) { self::assertExclusiveNamespace($pdo); - self::createIdentity($pdo, 1); + self::createIdentity($pdo); $pdo->exec('CREATE TABLE ' . self::MIGRATION_TABLE . ' (version INTEGER NOT NULL PRIMARY KEY, applied_at TIMESTAMP NOT NULL)'); return; } @@ -87,7 +93,7 @@ public static function ensure(PDO $pdo): void ); } - self::createIdentity($pdo, 1); + self::createIdentity($pdo); $pdo->exec('CREATE TABLE ' . self::MIGRATION_TABLE . ' (version INTEGER NOT NULL PRIMARY KEY, applied_at TIMESTAMP NOT NULL)'); } @@ -105,7 +111,7 @@ public static function assertReadyForUseReadOnly(PDO $pdo): void private static function assertReady(PDO $pdo, bool $initialize): void { if (self::tableExists($pdo, self::IDENTITY_TABLE)) { - if (self::validateIdentity($pdo) < self::SCHEMA_VERSION || !self::currentMigrationComplete($pdo)) { + if (!self::currentMigrationComplete($pdo)) { throw self::migrationRequired(); } self::assertExclusiveNamespace($pdo); @@ -139,12 +145,10 @@ private static function assertReady(PDO $pdo, bool $initialize): void public static function isFreshPending(PDO $pdo): bool { - if (!self::tableExists($pdo, self::IDENTITY_TABLE) - || !self::tableExists($pdo, self::MIGRATION_TABLE) - || self::validateIdentity($pdo) !== 1 - ) { + if (!self::tableExists($pdo, self::IDENTITY_TABLE) || !self::tableExists($pdo, self::MIGRATION_TABLE)) { return false; } + self::validateIdentity($pdo); $objects = self::namespaceObjects($pdo); $tables = self::actualTableNames($objects); sort($tables); @@ -164,18 +168,32 @@ public static function isFreshPending(PDO $pdo): bool public static function markCurrentVersion(PDO $pdo): void { self::validateIdentity($pdo); - if (!self::currentMigrationComplete($pdo)) { + if (!self::auditMigrationComplete($pdo, self::AUDIT_MIGRATION_VERSION)) { throw self::migrationRequired(); } + $migration = match ((string) $pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) { + 'mysql' => 'INSERT IGNORE INTO ' . self::MIGRATION_TABLE . ' (version, applied_at) VALUES (?, ?)', + default => 'INSERT INTO ' . self::MIGRATION_TABLE . ' (version, applied_at) VALUES (?, ?) ON CONFLICT (version) DO NOTHING', + }; + $pdo->prepare($migration)->execute([self::SCHEMA_VERSION, gmdate('Y-m-d H:i:s')]); $statement = $pdo->prepare('UPDATE ' . self::IDENTITY_TABLE . ' SET schema_version = ? WHERE catalog_identity_key = 1'); - $statement->execute([self::SCHEMA_VERSION]); + $statement->execute([self::IDENTITY_SCHEMA_VERSION]); } private static function currentMigrationComplete(PDO $pdo): bool + { + return self::auditMigrationComplete($pdo, self::SCHEMA_VERSION) + // A catalogue completed by a release before 0.9.0 (identity 4, marker 4) stays usable; + // its legacy numeric vocabulary codes are accepted by the readers. + || (self::validateIdentity($pdo) === self::LEGACY_IDENTITY_MAXIMUM + && self::auditMigrationComplete($pdo, self::AUDIT_MIGRATION_VERSION)); + } + + private static function auditMigrationComplete(PDO $pdo, int $minimumMarker): bool { return self::tableExists($pdo, self::MIGRATION_TABLE) && self::tableExists($pdo, self::AUDIT_TABLE) - && self::validateLegacyMarker($pdo) === self::SCHEMA_VERSION + && self::validateLegacyMarker($pdo) >= $minimumMarker && self::canSelectColumns($pdo, self::AUDIT_TABLE, self::auditColumns()); } @@ -205,11 +223,11 @@ private static function bindingResult(string $mode, ?string $name, ?string $loca ]; } - private static function createIdentity(PDO $pdo, int $schemaVersion = self::SCHEMA_VERSION): void + private static function createIdentity(PDO $pdo): void { $pdo->exec("CREATE TABLE " . self::IDENTITY_TABLE . " (catalog_identity_key INTEGER NOT NULL PRIMARY KEY, contract_id VARCHAR(128) NOT NULL UNIQUE, schema_version INTEGER NOT NULL, created_at TIMESTAMP NOT NULL, CHECK (catalog_identity_key = 1), CHECK (contract_id = 'openstatspec-strict-wide-table-v1'))"); $statement = $pdo->prepare('INSERT INTO ' . self::IDENTITY_TABLE . ' (catalog_identity_key, contract_id, schema_version, created_at) VALUES (?, ?, ?, ?)'); - $statement->execute([1, self::CONTRACT_ID, $schemaVersion, gmdate('Y-m-d H:i:s')]); + $statement->execute([1, self::CONTRACT_ID, self::IDENTITY_SCHEMA_VERSION, gmdate('Y-m-d H:i:s')]); } private static function validateIdentity(PDO $pdo): int @@ -224,7 +242,7 @@ private static function validateIdentity(PDO $pdo): int if (!is_array($identity) || ($identity['contract_id'] ?? null) !== self::CONTRACT_ID || $schemaVersion < 1 - || $schemaVersion > self::SCHEMA_VERSION + || $schemaVersion > self::LEGACY_IDENTITY_MAXIMUM ) { throw self::collision('The existing catalog_identity object has an unsupported owner, profile, or schema version.'); } @@ -283,7 +301,7 @@ private static function isRecognizedMarkerCatalog(PDO $pdo, array $collisions, i return false; } if ($markerVersion >= 3) { - return $canonicalComplete && ($markerVersion < self::SCHEMA_VERSION || $auditPresent); + return $canonicalComplete && ($markerVersion < self::AUDIT_MIGRATION_VERSION || $auditPresent); } return $canonicalComplete || $legacyComplete; } diff --git a/src/Sql/MySqlWideTableImporter.php b/src/Sql/MySqlWideTableImporter.php index 93784f9..d1bdf5d 100644 --- a/src/Sql/MySqlWideTableImporter.php +++ b/src/Sql/MySqlWideTableImporter.php @@ -469,6 +469,12 @@ private function dictionaryValue(mixed $value): array 'The Dolt profile rejects non-finite SPSS numeric values before mutation.', ); } + if ($value === 0.0 && fdiv(1.0, $value) < 0) { + throw new UnsupportedOperation( + DiagnosticCode::TargetCapabilityExceeded, + 'The MySQL-family profiles reject negative-zero SPSS dictionary values before mutation.', + ); + } return ['numeric', Binary64::encode($value), null]; } diff --git a/src/Sql/NormativeCatalog.php b/src/Sql/NormativeCatalog.php index 48f69fb..d24e46a 100644 --- a/src/Sql/NormativeCatalog.php +++ b/src/Sql/NormativeCatalog.php @@ -19,6 +19,15 @@ { private const SPEC_VERSION = '1.0'; + /** + * Text vocabularies of the variable catalogue, indexed by the SPSS dictionary + * code that earlier releases stored as a numeric string. Measurement level 0 + * (unknown) is stored as NULL. + */ + public const MEASUREMENT_LEVELS = [1 => 'nominal', 2 => 'ordinal', 3 => 'scale']; + public const VARIABLE_ROLES = ['input', 'target', 'both', 'none', 'partition', 'split']; + public const DISPLAY_ALIGNMENTS = ['left', 'right', 'center']; + public function __construct(private PDO $pdo) {} public function createTables(): void @@ -75,6 +84,34 @@ public function createTables(): void } } + /** Rewrite the legacy numeric vocabulary codes of earlier releases as text values. */ + public function migrateVocabularies(): void + { + foreach ([ + 'measurement_level' => [0 => null] + self::MEASUREMENT_LEVELS, + 'variable_role' => self::VARIABLE_ROLES, + 'display_alignment' => self::DISPLAY_ALIGNMENTS, + ] as $column => $values) { + $cases = ''; + foreach ($values as $code => $text) { + $cases .= " WHEN '" . $code . "' THEN " . ($text === null ? 'NULL' : "'" . $text . "'"); + } + $this->pdo->exec( + 'UPDATE variable SET ' . $column . ' = CASE ' . $column . $cases . ' END' + . " WHERE " . $column . " IN ('" . implode("', '", array_keys($values)) . "')", + ); + } + } + + /** @param array $values */ + private static function vocabularyText(mixed $code, array $values): ?string + { + if (!is_int($code) || !array_key_exists($code, $values)) { + throw new UnsupportedOperation(DiagnosticCode::InvalidSourceDataset, 'Unknown SPSS dictionary vocabulary code.'); + } + return $values[$code]; + } + /** Record one completed normative-catalogue migration idempotently. */ private function recordMigration(int $version): void { @@ -200,10 +237,10 @@ public function storeImportedDataset( $this->format($variable['writeFormatFamily'] ?? null), $this->integer($variable['writeFormatWidth'] ?? null), $this->integer($variable['writeFormatDecimals'] ?? null), - isset($display['measure']) ? (string) $display['measure'] : null, - isset($variable['role']) ? (string) $variable['role'] : null, + isset($display['measure']) ? self::vocabularyText($display['measure'], [0 => null] + self::MEASUREMENT_LEVELS) : null, + isset($variable['role']) ? self::vocabularyText($variable['role'], self::VARIABLE_ROLES) : null, $this->integer($display['columns'] ?? null), - isset($display['alignment']) ? (string) $display['alignment'] : null, + isset($display['alignment']) ? self::vocabularyText($display['alignment'], self::DISPLAY_ALIGNMENTS) : null, ]); $this->storeMissingRules($variableIds[$index + 1], $variable); $this->storeVariableAttributes($variableIds[$index + 1], $variable['attributes'] ?? []); diff --git a/tests/Core/CapabilityDeclarationTest.php b/tests/Core/CapabilityDeclarationTest.php index 29e3395..5c19b50 100644 --- a/tests/Core/CapabilityDeclarationTest.php +++ b/tests/Core/CapabilityDeclarationTest.php @@ -117,6 +117,7 @@ public function testDeclarationIsMachineReadableAndIncludesEveryProfileLimit(): 'nan' => 'reject_before_mutation', 'positive_infinity' => 'reject_before_mutation', 'negative_infinity' => 'reject_before_mutation', + 'negative_zero' => 'reject_before_mutation', 'system_missing' => 'sql_null', ], $profile['numeric_exception_policy']); self::assertSame(65_504, $profile['storage_evidence']['text']['observed_value_bytes']); diff --git a/tests/Integration/OfficialSpssConformanceManifestTest.php b/tests/Integration/OfficialSpssConformanceManifestTest.php index dae1a26..d8ced4c 100644 --- a/tests/Integration/OfficialSpssConformanceManifestTest.php +++ b/tests/Integration/OfficialSpssConformanceManifestTest.php @@ -25,14 +25,27 @@ final class OfficialSpssConformanceManifestTest extends TestCase { public function testEveryManifestRequirementRunsThroughEveryAvailableProfile(): void + { + $this->runManifest('spss-sav-zsav-1.0.json'); + } + + public function testEverySupplementRequirementRunsThroughEveryAvailableProfile(): void + { + $this->runManifest('spss-sav-zsav-1.0-supplement-1.json'); + } + + private function runManifest(string $file): void { $specification = $this->specificationRoot(); - $manifest = $this->manifest($specification); + $manifest = $this->manifest($specification, $file); + $supplement = isset($manifest['supplement_to']); $engine = new PhpSpssEngine(); foreach ($this->profiles() as $profile => $pdo) { $adapter = new SpssAdapter($pdo, $engine); - $this->assertRequiredCapabilities($manifest, $adapter, $profile); + if (!$supplement) { + $this->assertRequiredCapabilities($manifest, $adapter, $profile); + } $executed = []; foreach ($manifest['fixtures'] as $fixture) { self::assertIsArray($fixture); @@ -65,11 +78,21 @@ public function testEveryManifestRequirementRunsThroughEveryAvailableProfile(): continue; } + $special = array_intersect($expectations, ['negative_zero_preserved_refused_or_reported', 'nan_preserved_refused_or_declared_null']); + if ($special !== []) { + self::assertSame(['import', 'semantic_round_trip'], $directions); + $this->assertSpecialNumericOutcome($pdo, $adapter, $profile, $id, array_values($special)[0]); + $executed[] = $id; + continue; + } + $sourcePath = $specification . '/conformance/' . $source; self::assertFileExists($sourcePath, 'Missing official fixture: ' . $id); $extension = strtolower(pathinfo($sourcePath, PATHINFO_EXTENSION)); self::assertContains($extension, ['sav', 'zsav']); - self::assertContains('import', $directions, $id . ': fixture must exercise import'); + if (!$supplement) { + self::assertContains('import', $directions, $id . ': fixture must exercise import'); + } $token = bin2hex(random_bytes(8)); $datasetName = 'official_' . $profile . '_' . str_replace('-', '_', $id) . '_' . $token; $targetPath = sys_get_temp_dir() . '/openstatspec-official-' . $token . '.' . $extension; @@ -81,10 +104,10 @@ public function testEveryManifestRequirementRunsThroughEveryAvailableProfile(): self::assertSame([], $import->diagnostics); $this->assertCanonicalShape($pdo, $datasetName, $sourceDataset); if (is_array($expectedCatalog)) { - $this->assertExpectedCatalog($pdo, $datasetName, $expectedCatalog, $profile . '/' . $id); + $this->assertExpectedCatalog($pdo, $datasetName, $expectedCatalog, $profile . '/' . $id, $supplement); } - if (in_array('export', $directions, true)) { + if (in_array('export', $directions, true) || in_array('semantic_round_trip', $directions, true)) { $export = $adapter->export($datasetName, $targetPath); self::assertSame([], $export->diagnostics); } @@ -99,6 +122,22 @@ public function testEveryManifestRequirementRunsThroughEveryAvailableProfile(): self::assertSame($sourceDataset->technicalMetadata->encoding, $roundTrip->technicalMetadata->encoding, $context . ': source encoding'); $roundTripCompared = true; } + if (in_array('attribute_export_order', $expectations, true)) { + self::assertIsArray($expectedCatalog); + $exported = $engine->read($targetPath); + self::assertSame( + $expectedCatalog['dataset_attribute_export_order'], + array_map(static fn(\SPSS\Sav\FileAttribute $attribute): string => $attribute->name, $exported->metadata->attributes()), + $profile . '/' . $id . ': dataset attribute export order', + ); + $exportedVariables = []; + foreach ($exported->variables() as $variable) { + $exportedVariables[$variable->name] = array_map(static fn(\SPSS\Sav\VariableAttribute $attribute): string => $attribute->name, $variable->attributes()); + } + foreach ($expectedCatalog['variable_attribute_export_order'] as $expectedVariable) { + self::assertSame($expectedVariable['names'], $exportedVariables[$expectedVariable['variable']] ?? null, $profile . '/' . $id . ': variable attribute export order'); + } + } foreach ($expectations as $expectation) { $this->assertCanonicalExpectation($pdo, $datasetName, $expectation, $roundTripCompared); } @@ -112,20 +151,79 @@ public function testEveryManifestRequirementRunsThroughEveryAvailableProfile(): } /** @return array */ - private function manifest(string $specification): array + private function manifest(string $specification, string $file): array { - $contents = file_get_contents($specification . '/conformance/spss-sav-zsav-1.0.json'); + $contents = file_get_contents($specification . '/conformance/' . $file); if (!is_string($contents)) { throw new RuntimeException('Could not read the official conformance manifest.'); } $manifest = json_decode($contents, true, flags: JSON_THROW_ON_ERROR); self::assertIsArray($manifest); self::assertSame('1.0', $manifest['manifest_version'] ?? null); - self::assertIsArray($manifest['required_capabilities'] ?? null); + if (!isset($manifest['supplement_to'])) { + self::assertIsArray($manifest['required_capabilities'] ?? null); + } self::assertIsArray($manifest['fixtures'] ?? null); return $manifest; } + /** + * Generates the runner-made fixture of the supplement (one numeric variable, + * three cases) and checks that the special value is stored exactly, refused + * before mutation, or (negative zero only) imported with a reported loss. + */ + private function assertSpecialNumericOutcome(PDO $pdo, SpssAdapter $adapter, string $profile, string $id, string $expectation): void + { + $bits = $expectation === 'negative_zero_preserved_refused_or_reported' + ? ['0000000000000000', '8000000000000000', '3ff0000000000000'] + : ['3ff0000000000000', '7ff8000000000000', '4000000000000000']; + $variable = new VariableMetadata( + 'value', + \SPSS\Sav\VariableType::NUMERIC, + 0, + new \SPSS\Sav\VariableFormat(5, 8, 2), + new \SPSS\Sav\VariableFormat(5, 8, 2), + valueLabels: new ValueLabelSet([], ['value']), + dictionaryIndex: 1, + ); + $rows = array_map(static function (string $value): array { + $float = unpack('E', (string) hex2bin($value)); + self::assertIsArray($float); + return [$float[1]]; + }, $bits); + $sourcePath = sys_get_temp_dir() . '/openstatspec-' . $id . '-' . bin2hex(random_bytes(6)) . '.sav'; + (new PhpSpssEngine())->write($sourcePath, new Dataset(new VariableDictionary([$variable]), $rows, new FileMetadata(), new FileTechnicalMetadata(sourceFormat: 'sav'))); + $datasetName = 'special_' . $profile . '_' . str_replace('-', '_', $id) . '_' . bin2hex(random_bytes(5)); + $adapter->migrateCatalog(); + $tablesBefore = $this->tableNames($pdo); + $context = $profile . '/' . $id; + + try { + $import = $adapter->import($sourcePath, $datasetName); + } catch (UnsupportedOperation) { + self::assertSame($tablesBefore, $this->tableNames($pdo), $context . ': refusal changed the schema'); + self::assertSame(0, $this->scalarCount($pdo, 'SELECT COUNT(*) FROM dataset WHERE dataset_name = ?', [$datasetName]), $context . ': refusal left a dataset row'); + return; + } finally { + @unlink($sourcePath); + } + + $datasetId = (string) $this->scalar($pdo, 'SELECT dataset_id FROM dataset WHERE dataset_name = ?', [$datasetName]); + $table = (string) $this->scalar($pdo, 'SELECT physical_table_name FROM dataset WHERE dataset_id = ?', [$datasetId]); + $column = (string) $this->scalar($pdo, "SELECT physical_name FROM variable WHERE dataset_id = ? AND source_name = 'value'", [$datasetId]); + $quote = (new \OpenStatSpec\Sql\Connection($pdo))->profile; + $statement = $pdo->query('SELECT ' . $quote->quoteIdentifier($column) . ' FROM ' . $quote->quoteIdentifier($table) . ' ORDER BY ' . $quote->quoteIdentifier('__case_ordinal')); + self::assertInstanceOf(\PDOStatement::class, $statement); + $stored = array_map(static fn(mixed $value): string => bin2hex(pack('E', (float) $value)), $statement->fetchAll(PDO::FETCH_COLUMN)); + if ($stored === $bits) { + return; + } + self::assertSame('negative_zero_preserved_refused_or_reported', $expectation, $context . ': NaN was neither stored exactly nor refused'); + $reported = $this->scalarCount($pdo, "SELECT COUNT(*) FROM fidelity_event WHERE dataset_id = ? AND direction = 'import' AND source_item = 'value'", [$datasetId]); + self::assertGreaterThan(0, $reported, $context . ': negative zero changed without a reported loss'); + self::assertNotSame([], $import->diagnostics, $context); + } + /** @param array $manifest */ private function assertRequiredCapabilities(array $manifest, SpssAdapter $adapter, string $profile): void { @@ -145,10 +243,52 @@ private function assertRequiredCapabilities(array $manifest, SpssAdapter $adapte } /** @param array $expected */ - private function assertExpectedCatalog(PDO $pdo, string $datasetName, array $expected, string $context): void + private function assertExpectedCatalog(PDO $pdo, string $datasetName, array $expected, string $context, bool $supplement = false): void { $datasetId = (string) $this->scalar($pdo, 'SELECT dataset_id FROM dataset WHERE dataset_name = ?', [$datasetName]); + if (array_key_exists('dataset', $expected)) { + $row = $this->rows($pdo, 'SELECT * FROM dataset WHERE dataset_id = ?', [$datasetId])[0]; + self::assertSame($expected['dataset'], array_intersect_key($row, $expected['dataset']), $context . ': dataset row'); + } + + if (array_key_exists('catalog_identity', $expected)) { + $row = $this->rows($pdo, 'SELECT contract_id, schema_version FROM catalog_identity', [])[0]; + self::assertSame($expected['catalog_identity'], ['contract_id' => $row['contract_id'], 'schema_version' => (int) $row['schema_version']], $context . ': catalog identity'); + } + + if (array_key_exists('variables', $expected)) { + foreach ($expected['variables'] as $variable) { + $rows = $this->rows($pdo, 'SELECT measurement_level, variable_role, display_alignment FROM variable WHERE dataset_id = ? AND source_name = ?', [$datasetId, $variable['variable']]); + self::assertCount(1, $rows, $context . ': variable ' . $variable['variable']); + $columns = $variable; + unset($columns['variable']); + self::assertSame($columns, array_intersect_key($rows[0], $columns), $context . ': vocabulary of ' . $variable['variable']); + } + } + + if (array_key_exists('missing_rules', $expected)) { + foreach ($expected['missing_rules'] as $rule) { + $rows = $this->rows($pdo, 'SELECT rule.ordinal, rule.rule_kind, rule.lower_special, rule.numeric_lower, rule.upper_special, rule.numeric_upper FROM missing_rule rule JOIN variable ON variable.variable_id = rule.variable_id WHERE variable.dataset_id = ? AND variable.source_name = ? AND rule.ordinal = ?', [$datasetId, $rule['variable'], $rule['ordinal']]); + self::assertCount(1, $rows, $context . ': missing rule of ' . $rule['variable']); + $actual = $rows[0]; + foreach (['numeric_lower', 'numeric_upper'] as $bound) { + $actual[$bound] = $actual[$bound] === null ? null : (float) $actual[$bound]; + } + $actual['ordinal'] = (int) $actual['ordinal']; + self::assertSame($rule, ['variable' => $rule['variable']] + $actual, $context . ': missing rule endpoints'); + } + } + + if ($supplement && array_key_exists('multiple_response_sets', $expected)) { + foreach ($expected['multiple_response_sets'] as $set) { + $rows = $this->rows($pdo, 'SELECT set_name AS name, category_label_behavior, label_source FROM multiple_response_set WHERE dataset_id = ? AND set_name = ?', [$datasetId, $set['name']]); + self::assertCount(1, $rows, $context . ': multiple-response set ' . $set['name']); + self::assertSame($set, array_intersect_key($rows[0], $set), $context . ': multiple-response vocabulary'); + } + unset($expected['multiple_response_sets']); + } + if (array_key_exists('weight_variable', $expected)) { $actual = $this->scalar($pdo, 'SELECT variable.source_name FROM dataset_weight_variable weight JOIN variable ON variable.variable_id = weight.variable_id WHERE weight.dataset_id = ?', [$datasetId]); self::assertSame($expected['weight_variable'], $actual, $context . ': weight variable'); @@ -277,7 +417,8 @@ private function assertCanonicalExpectation(PDO $pdo, string $datasetName, strin 'weight_variable' => self::assertSame(1, $count('SELECT COUNT(*) FROM dataset_weight_variable WHERE dataset_id = ?')), 'variable_labels' => self::assertGreaterThan(0, $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND variable_label IS NOT NULL')), 'print_write_formats' => self::assertSame($count('SELECT COUNT(*) FROM variable WHERE dataset_id = ?'), $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND print_format_family IS NOT NULL AND write_format_family IS NOT NULL')), - 'measurement_level' => self::assertSame($count('SELECT COUNT(*) FROM variable WHERE dataset_id = ?'), $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND measurement_level IS NOT NULL')), + // An unknown measurement level is stored as NULL (Conformance Supplement 0.6). + 'measurement_level' => self::assertGreaterThan(0, $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND measurement_level IS NOT NULL')), 'variable_role' => self::assertSame($count('SELECT COUNT(*) FROM variable WHERE dataset_id = ?'), $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND variable_role IS NOT NULL')), 'display_width' => self::assertSame($count('SELECT COUNT(*) FROM variable WHERE dataset_id = ?'), $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND display_width IS NOT NULL')), 'display_alignment' => self::assertSame($count('SELECT COUNT(*) FROM variable WHERE dataset_id = ?'), $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND display_alignment IS NOT NULL')), @@ -299,6 +440,12 @@ private function assertCanonicalExpectation(PDO $pdo, string $datasetName, strin 'multiple_response_string_counted_value' => self::assertGreaterThan(0, $count("SELECT COUNT(*) FROM multiple_response_set WHERE dataset_id = ? AND counted_value_kind = 'string' AND counted_string_value IS NOT NULL")), 'multiple_response_category_label_behavior' => self::assertGreaterThan(0, $count('SELECT COUNT(*) FROM multiple_response_set WHERE dataset_id = ? AND category_label_behavior IS NOT NULL')), 'multiple_response_label_source' => self::assertGreaterThan(0, $count('SELECT COUNT(*) FROM multiple_response_set WHERE dataset_id = ? AND label_source IS NOT NULL')), + // Checked against expected_catalog or after the export above. + 'dataset_spec_version', 'catalog_schema_version', 'measurement_level_vocabulary', 'variable_role_vocabulary', + 'display_alignment_vocabulary', 'category_label_behavior_vocabulary', 'label_source_vocabulary', + 'lowest_highest_null_endpoints', 'attribute_export_order' => null, + 'attribute_comparison_by_name' => self::assertTrue($roundTripCompared, $expectation . ' requires a semantic round trip'), + 'physical_table_schema_rule' => $this->assertPhysicalTableSchema($pdo, $datasetId), default => throw new RuntimeException('Unimplemented conformance expectation: ' . $expectation), }; } @@ -371,6 +518,17 @@ private function assertPreflightFailure(PDO $pdo, string $profile, array $capabi self::assertSame(0, $this->scalarCount($pdo, 'SELECT COUNT(*) FROM datasets WHERE dataset_name = ?', [$datasetName])); } + private function assertPhysicalTableSchema(PDO $pdo, string $datasetId): void + { + $schema = $this->scalar($pdo, 'SELECT physical_table_schema FROM dataset WHERE dataset_id = ?', [$datasetId]); + $namespace = match ((string) $pdo->getAttribute(PDO::ATTR_DRIVER_NAME)) { + 'sqlite' => null, + 'pgsql' => $this->scalar($pdo, 'SELECT current_schema()', []), + default => $this->scalar($pdo, 'SELECT DATABASE()', []), + }; + self::assertContains($schema, [null, $namespace]); + } + /** @return list */ private function tableNames(PDO $pdo): array { @@ -460,14 +618,30 @@ private function normativeVariables(array $variables): array 'alignment' => $variable->alignment, 'columns' => $variable->columns, 'role' => $variable->role, - 'attributes' => $variable->attributes(), + 'attributes' => $this->attributesByName($variable->attributes()), ], $variables); } /** @return array */ private function normativeMetadata(FileMetadata $metadata): array { - return ['label' => $metadata->label, 'weightVariableName' => $metadata->weightVariableName, 'documents' => $metadata->documents(), 'attributes' => $metadata->attributes(), 'variableSets' => $metadata->variableSets(), 'multipleResponseSets' => $metadata->multipleResponseSets()]; + return ['label' => $metadata->label, 'weightVariableName' => $metadata->weightVariableName, 'documents' => $metadata->documents(), 'attributes' => $this->attributesByName($metadata->attributes()), 'variableSets' => $metadata->variableSets(), 'multipleResponseSets' => $metadata->multipleResponseSets()]; + } + + /** + * A round trip compares attribute value arrays by name, not the order of names. + * + * @param list<\SPSS\Sav\FileAttribute|\SPSS\Sav\VariableAttribute> $attributes + * @return array> + */ + private function attributesByName(array $attributes): array + { + $byName = []; + foreach ($attributes as $attribute) { + $byName[$attribute->name] = $attribute->values(); + } + ksort($byName, SORT_STRING); + return $byName; } /** @return array */ diff --git a/tests/Spss/SpssAdapterTest.php b/tests/Spss/SpssAdapterTest.php index 374a1f6..dd1b464 100644 --- a/tests/Spss/SpssAdapterTest.php +++ b/tests/Spss/SpssAdapterTest.php @@ -71,25 +71,25 @@ public function testSuccessfulMigrationAdvancesOlderIdentityVersion(): void { $pdo = new PDO('sqlite::memory:', options: [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); CatalogOwnership::ensure($pdo); - $pdo->exec('UPDATE catalog_identity SET schema_version = 1'); + $pdo->exec('UPDATE catalog_identity SET schema_version = 4'); (new SpssAdapter($pdo, new FakeSpssEngine($this->fixture())))->migrateCatalog(); - self::assertSame([['schema_version' => 4]], self::rows($pdo, 'SELECT schema_version FROM catalog_identity')); + self::assertSame([['schema_version' => 1]], self::rows($pdo, 'SELECT schema_version FROM catalog_identity')); } public function testFailedMigrationDoesNotAdvanceOlderIdentityVersion(): void { $pdo = new PDO('sqlite::memory:', options: [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); CatalogOwnership::ensure($pdo); - $pdo->exec('UPDATE catalog_identity SET schema_version = 1'); + $pdo->exec('UPDATE catalog_identity SET schema_version = 4'); $pdo->exec('CREATE TABLE datasets (application_id INTEGER PRIMARY KEY)'); try { (new SpssAdapter($pdo, new FakeSpssEngine($this->fixture())))->migrateCatalog(); self::fail('A malformed legacy catalogue unexpectedly migrated.'); } catch (\PDOException|UnsupportedOperation) { - self::assertSame([['schema_version' => 1]], self::rows($pdo, 'SELECT schema_version FROM catalog_identity')); + self::assertSame([['schema_version' => 4]], self::rows($pdo, 'SELECT schema_version FROM catalog_identity')); } } @@ -115,7 +115,7 @@ public function testImportRequiresExplicitMigrationForOlderIdentityWithoutJourna $result = $adapter->import('fixture.sav', 'Old catalog import'); self::assertSame(2, $result->caseCount); - self::assertSame([['schema_version' => 4]], self::rows($pdo, 'SELECT schema_version FROM catalog_identity')); + self::assertSame([['schema_version' => 1]], self::rows($pdo, 'SELECT schema_version FROM catalog_identity')); } public function testExportRequiresExplicitMigrationForOlderIdentityWithoutJournalMutation(): void @@ -123,7 +123,7 @@ public function testExportRequiresExplicitMigrationForOlderIdentityWithoutJourna $pdo = new PDO('sqlite::memory:', options: [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $adapter = new SpssAdapter($pdo, new FakeSpssEngine($this->fixture())); $adapter->import('fixture.sav', 'Old catalog export'); - $pdo->exec('UPDATE catalog_identity SET schema_version = 1'); + $pdo->exec('DELETE FROM openstatspec_schema_migration WHERE version = 5'); $before = self::rows($pdo, 'SELECT COUNT(*) AS operation_count FROM operation_catalog'); try { @@ -142,7 +142,37 @@ public function testExportRequiresExplicitMigrationForOlderIdentityWithoutJourna unlink($target); self::assertSame(2, $result->caseCount); - self::assertSame([['schema_version' => 4]], self::rows($pdo, 'SELECT schema_version FROM catalog_identity')); + self::assertSame([['schema_version' => 1]], self::rows($pdo, 'SELECT schema_version FROM catalog_identity')); + } + + public function testLegacyNumericVocabularyCatalogExportsAndMigratesToText(): void + { + $pdo = new PDO('sqlite::memory:', options: [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); + $engine = new FakeSpssEngine($this->fixture()); + $adapter = new SpssAdapter($pdo, $engine); + $adapter->import('fixture.sav', 'legacy vocabulary'); + // The state a 0.8 release leaves: numeric codes, identity 4, migration marker 4. + $pdo->exec("UPDATE variable SET measurement_level = '1', variable_role = '3', display_alignment = '2'"); + $pdo->exec('UPDATE catalog_identity SET schema_version = 4'); + $pdo->exec('DELETE FROM openstatspec_schema_migration WHERE version = 5'); + $target = sys_get_temp_dir() . '/oss-' . bin2hex(random_bytes(8)) . '.sav'; + + try { + $adapter->export('legacy vocabulary', $target); + } finally { + @unlink($target); + } + $exported = $engine->lastWrite()['dataset']->variables()[0]; + self::assertSame([Measure::NOMINAL, VariableRole::NONE, Alignment::CENTER], [$exported->measure, $exported->role, $exported->alignment]); + + $adapter->migrateCatalog(); + + self::assertSame( + [['measurement_level' => 'nominal', 'variable_role' => 'none', 'display_alignment' => 'center']], + self::rows($pdo, 'SELECT DISTINCT measurement_level, variable_role, display_alignment FROM variable'), + ); + self::assertSame([['schema_version' => 1]], self::rows($pdo, 'SELECT schema_version FROM catalog_identity')); + self::assertSame([['version' => 5]], self::rows($pdo, 'SELECT version FROM openstatspec_schema_migration WHERE version = 5')); } public function testExportIsReadOnlyAndPreservesDestinationOnWriterFailure(): void @@ -277,7 +307,7 @@ public function testTypedDatasetImportCreatesWideTableAndExportPreservesSupporte $import = $adapter->import('fixture.sav', 'Customer survey'); self::assertSame('Customer survey', $import->datasetName); - self::assertSame([['schema_version' => 4]], self::rows($pdo, 'SELECT schema_version FROM catalog_identity')); + self::assertSame([['schema_version' => 1]], self::rows($pdo, 'SELECT schema_version FROM catalog_identity')); self::assertSame(2, $import->caseCount); self::assertSame([], $import->diagnostics); self::assertMatchesRegularExpression('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/', $import->operationId); @@ -1142,7 +1172,7 @@ public function testMigrateCatalogBackfillsLegacyDatasetsAndIsIdempotent(): void self::rows($pdo, 'SELECT spec_version, source_format, physical_table_name, dataset_name, source_case_count FROM dataset'), ); self::assertSame( - [['version' => 1], ['version' => 2], ['version' => 3], ['version' => 4]], + [['version' => 1], ['version' => 2], ['version' => 3], ['version' => 4], ['version' => 5]], self::rows($pdo, 'SELECT version FROM openstatspec_schema_migration ORDER BY version'), ); self::assertSame( diff --git a/tests/Sql/CatalogOwnershipTest.php b/tests/Sql/CatalogOwnershipTest.php index a7ca3b9..73a46f5 100644 --- a/tests/Sql/CatalogOwnershipTest.php +++ b/tests/Sql/CatalogOwnershipTest.php @@ -216,7 +216,7 @@ public function testRegisteredPhysicalDataTableIsAllowed(): void CatalogOwnership::ensure($pdo); - self::assertSame(4, (int) $this->query($pdo, 'SELECT schema_version FROM catalog_identity')->fetchColumn()); + self::assertSame(1, (int) $this->query($pdo, 'SELECT schema_version FROM catalog_identity')->fetchColumn()); } public function testCurrentVersionCannotBeMarkedBeforeAuditMigrationCompletes(): void @@ -388,7 +388,7 @@ public function testReleasedCanonicalCatalogCanBeReclaimedFromMigrationMarker(): CatalogOwnership::ensure($pdo); self::assertSame('openstatspec-strict-wide-table-v1', $this->query($pdo, 'SELECT contract_id FROM catalog_identity')->fetchColumn()); - self::assertSame(3, (int) $this->query($pdo, 'SELECT schema_version FROM catalog_identity')->fetchColumn()); + self::assertSame(1, (int) $this->query($pdo, 'SELECT schema_version FROM catalog_identity')->fetchColumn()); } public function testIncompleteLegacyCatalogCannotClaimTheNamespace(): void diff --git a/tests/Transformation/Audit/TransformationAuditMigratorTest.php b/tests/Transformation/Audit/TransformationAuditMigratorTest.php index 0312b39..583421a 100644 --- a/tests/Transformation/Audit/TransformationAuditMigratorTest.php +++ b/tests/Transformation/Audit/TransformationAuditMigratorTest.php @@ -124,7 +124,7 @@ public function testFreshSqliteMigrationCreatesTheExactCompactAuditTable(): void ); } - public function testAdapterMigrationRecordsFreshVersionsOneThroughFourExactlyOnce(): void + public function testAdapterMigrationRecordsFreshVersionsOneThroughFiveExactlyOnce(): void { $pdo = new PDO('sqlite::memory:', options: [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $adapter = new SpssAdapter($pdo); @@ -132,8 +132,8 @@ public function testAdapterMigrationRecordsFreshVersionsOneThroughFourExactlyOnc $adapter->migrateCatalog(); $adapter->migrateCatalog(); - self::assertSame([1, 2, 3, 4], $this->migrationVersions($pdo)); - self::assertSame(4, (int) $this->query($pdo, 'SELECT schema_version FROM catalog_identity')->fetchColumn()); + self::assertSame([1, 2, 3, 4, 5], $this->migrationVersions($pdo)); + self::assertSame(1, (int) $this->query($pdo, 'SELECT schema_version FROM catalog_identity')->fetchColumn()); self::assertSame( ['transformation_apply'], $this->query($pdo, "SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'transformation_apply'")->fetchAll(PDO::FETCH_COLUMN), From 27d67ce05861229aef510394420ce7e867713df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B5nis=20Ormisson?= Date: Tue, 1 Dec 2026 14:31:54 +0200 Subject: [PATCH 3/7] Prepare PHP 0.9.0 release metadata --- CHANGELOG.md | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2866d63..4baa25f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,50 @@ ## [Unreleased] +## [0.9.0] - 2026-12-01 + +Targets OpenStatSpec specification `v0.6.0` and passes its Conformance +Supplement 0.6 manifests for every profile this adapter claims. The Frontend +0.1 boundary case is skipped: PHP does not claim the Frontend 0.1 contract. + +### Changed + +- Frontend requests that break the request schema now fail with + `request_schema_invalid` instead of `plan_schema_invalid`. So do input + schemas with two names that are equal case-insensitively and numeric value + labels on a string variable. +- Case-insensitive name matching lowercases each code point on its own, so + the context-sensitive final sigma rule of `mb_strtolower()` no longer + applies. +- A `*` or `COMMENT` comment ends only at a period followed by whitespace or + the end of input. A name may contain an inner period (`a.b`). `AND`, `OR`, + `NOT`, `TO`, `EQ`, `NE`, `LT`, `LE`, `GT`, `GE`, `BY`, `ALL` and `WITH` are + never variable names or `INTO` targets. `FORMATS x (F8)` means `F8.0`. +- `VAR LAB` and `VAL LAB` are no longer accepted as abbreviations; they fail + with `unsupported_spss_command`. +- A replace recode whose target is not its source fails plan validation with + `target_already_exists` (before: `type_mismatch` at binding). +- The catalogue stores `variable.measurement_level`, `variable_role` and + `display_alignment` as text (`nominal`, `input`, `left` and so on); an + unknown measurement level is NULL. Readers still accept the numeric codes + that earlier releases wrote. `migrateCatalog()` rewrites them as text. +- `catalog_identity.schema_version` is now 1, the version of the + specification's `schema-outline.sql`. The adapter keeps its own migration + counter in `openstatspec_schema_migration`, now at 5. A catalogue completed + by 0.8.x stays usable without migration; run `migrateCatalog()` to convert + its vocabulary and identity. +- Exported dataset and variable attributes are ordered by name in code-point + order on every server. + +### Fixed + +- Negative zero in a numeric case value, and in a MySQL-family dictionary + value, is refused before mutation (`target_capability_exceeded`). Before, it + was stored silently as positive zero. The Dolt capability declaration lists + the refusal. +- A command at the end of the program without its terminating period now + fails with `spss_syntax_error` even when the command is unsupported. + ## [0.8.4] - 2026-12-01 ### Fixed @@ -222,7 +266,8 @@ ownership checks are retained; this release requires no new migration. - Pinned active conformance fixtures and capabilities to released OpenStatSpec specification v0.1.0 at commit `d287c2cde9ade71f04e27dd012caec876901aed5`. -[Unreleased]: https://github.com/OpenStatSpec/php/compare/v0.8.1...HEAD +[Unreleased]: https://github.com/OpenStatSpec/php/compare/v0.9.0...HEAD +[0.9.0]: https://github.com/OpenStatSpec/php/compare/v0.8.3...v0.9.0 [0.8.1]: https://github.com/OpenStatSpec/php/compare/v0.8.0...v0.8.1 [0.8.0]: https://github.com/OpenStatSpec/php/compare/v0.7.1...v0.8.0 [0.7.1]: https://github.com/OpenStatSpec/php/compare/v0.7.0...v0.7.1 From fef3bb6970633a4eca7719d1a58785d2ad8582cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B5nis=20Ormisson?= Date: Tue, 1 Dec 2026 15:06:36 +0200 Subject: [PATCH 4/7] Follow the updated conformance supplement 0.6 Check the termination rule before refusing a Frontend 0.2 star comment, so trailing comment text without its period fails with spss_syntax_error. Write unknown for an unknown measurement level, as the supplement now allows, and restore the strict published measurement_level check. Count the 16th Frontend 0.1 supplement case. --- CHANGELOG.md | 10 ++++++---- src/Frontend/Spss/Lexer.php | 6 ++++-- src/Sql/CanonicalWideTableExporter.php | 2 +- src/Sql/NormativeCatalog.php | 15 +++++++-------- .../Spss/Conformance/SpssFrontend02Test.php | 2 +- .../OfficialSpssConformanceManifestTest.php | 3 +-- .../Conformance/ManifestInventoryTest.php | 2 +- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4baa25f..fad3cfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,9 +26,10 @@ Supplement 0.6 manifests for every profile this adapter claims. The Frontend - A replace recode whose target is not its source fails plan validation with `target_already_exists` (before: `type_mismatch` at binding). - The catalogue stores `variable.measurement_level`, `variable_role` and - `display_alignment` as text (`nominal`, `input`, `left` and so on); an - unknown measurement level is NULL. Readers still accept the numeric codes - that earlier releases wrote. `migrateCatalog()` rewrites them as text. + `display_alignment` as text (`nominal`, `input`, `left` and so on, with + `unknown` for an unknown measurement level). Readers still accept the + numeric codes that earlier releases wrote. `migrateCatalog()` rewrites them + as text. - `catalog_identity.schema_version` is now 1, the version of the specification's `schema-outline.sql`. The adapter keeps its own migration counter in `openstatspec_schema_migration`, now at 5. A catalogue completed @@ -44,7 +45,8 @@ Supplement 0.6 manifests for every profile this adapter claims. The Frontend was stored silently as positive zero. The Dolt capability declaration lists the refusal. - A command at the end of the program without its terminating period now - fails with `spss_syntax_error` even when the command is unsupported. + fails with `spss_syntax_error` even when the command is unsupported or a + `*` comment that Frontend 0.2 does not accept. ## [0.8.4] - 2026-12-01 diff --git a/src/Frontend/Spss/Lexer.php b/src/Frontend/Spss/Lexer.php index 62d60dc..f1f0e5c 100644 --- a/src/Frontend/Spss/Lexer.php +++ b/src/Frontend/Spss/Lexer.php @@ -39,10 +39,12 @@ public function tokenize(string $source, bool $officialV03 = false): array $this->comment($source, $offset, $line, $column, false); continue; } + // The termination rule comes first: trailing text without its period is a syntax error. + $terminated = preg_match('/\.(?:\s|\z)/', $source, offset: $offset) === 1; $this->fail( new SourceSpan($offset, $offset + 1, $line, $column, $line, $column + 1), - 'Leading-star comments are not supported.', - 'unsupported_spss_command', + $terminated ? 'Leading-star comments are not supported.' : 'Every SPSS command must end with a period.', + $terminated ? 'unsupported_spss_command' : 'spss_syntax_error', ); } diff --git a/src/Sql/CanonicalWideTableExporter.php b/src/Sql/CanonicalWideTableExporter.php index 949286e..c56c0a2 100644 --- a/src/Sql/CanonicalWideTableExporter.php +++ b/src/Sql/CanonicalWideTableExporter.php @@ -81,7 +81,7 @@ public function export(string $datasetName, string $targetFormat = 'sav'): array label: $variable['variable_label'] === null ? null : $this->text($variable['variable_label']), valueLabels: new ValueLabelSet($labels, [$name]), missingValues: $this->missingValues($missingByVariable[$variableId] ?? []), - measure: Measure::from($this->vocabularyCode($variable['measurement_level'], [0 => 'unknown'] + NormativeCatalog::MEASUREMENT_LEVELS) ?? 0), + measure: Measure::from($this->vocabularyCode($variable['measurement_level'], NormativeCatalog::MEASUREMENT_LEVELS) ?? 0), alignment: Alignment::from($this->vocabularyCode($variable['display_alignment'], NormativeCatalog::DISPLAY_ALIGNMENTS) ?? 0), columns: max(0, $this->integer($variable['display_width'] ?? 8)), role: VariableRole::from($this->vocabularyCode($variable['variable_role'], NormativeCatalog::VARIABLE_ROLES) ?? 0), diff --git a/src/Sql/NormativeCatalog.php b/src/Sql/NormativeCatalog.php index d24e46a..f021a4f 100644 --- a/src/Sql/NormativeCatalog.php +++ b/src/Sql/NormativeCatalog.php @@ -21,10 +21,9 @@ /** * Text vocabularies of the variable catalogue, indexed by the SPSS dictionary - * code that earlier releases stored as a numeric string. Measurement level 0 - * (unknown) is stored as NULL. + * code that earlier releases stored as a numeric string. */ - public const MEASUREMENT_LEVELS = [1 => 'nominal', 2 => 'ordinal', 3 => 'scale']; + public const MEASUREMENT_LEVELS = ['unknown', 'nominal', 'ordinal', 'scale']; public const VARIABLE_ROLES = ['input', 'target', 'both', 'none', 'partition', 'split']; public const DISPLAY_ALIGNMENTS = ['left', 'right', 'center']; @@ -88,13 +87,13 @@ public function createTables(): void public function migrateVocabularies(): void { foreach ([ - 'measurement_level' => [0 => null] + self::MEASUREMENT_LEVELS, + 'measurement_level' => self::MEASUREMENT_LEVELS, 'variable_role' => self::VARIABLE_ROLES, 'display_alignment' => self::DISPLAY_ALIGNMENTS, ] as $column => $values) { $cases = ''; foreach ($values as $code => $text) { - $cases .= " WHEN '" . $code . "' THEN " . ($text === null ? 'NULL' : "'" . $text . "'"); + $cases .= " WHEN '" . $code . "' THEN '" . $text . "'"; } $this->pdo->exec( 'UPDATE variable SET ' . $column . ' = CASE ' . $column . $cases . ' END' @@ -103,8 +102,8 @@ public function migrateVocabularies(): void } } - /** @param array $values */ - private static function vocabularyText(mixed $code, array $values): ?string + /** @param array $values */ + private static function vocabularyText(mixed $code, array $values): string { if (!is_int($code) || !array_key_exists($code, $values)) { throw new UnsupportedOperation(DiagnosticCode::InvalidSourceDataset, 'Unknown SPSS dictionary vocabulary code.'); @@ -237,7 +236,7 @@ public function storeImportedDataset( $this->format($variable['writeFormatFamily'] ?? null), $this->integer($variable['writeFormatWidth'] ?? null), $this->integer($variable['writeFormatDecimals'] ?? null), - isset($display['measure']) ? self::vocabularyText($display['measure'], [0 => null] + self::MEASUREMENT_LEVELS) : null, + isset($display['measure']) ? self::vocabularyText($display['measure'], self::MEASUREMENT_LEVELS) : null, isset($variable['role']) ? self::vocabularyText($variable['role'], self::VARIABLE_ROLES) : null, $this->integer($display['columns'] ?? null), isset($display['alignment']) ? self::vocabularyText($display['alignment'], self::DISPLAY_ALIGNMENTS) : null, diff --git a/tests/Frontend/Spss/Conformance/SpssFrontend02Test.php b/tests/Frontend/Spss/Conformance/SpssFrontend02Test.php index 8734a8f..46944d0 100644 --- a/tests/Frontend/Spss/Conformance/SpssFrontend02Test.php +++ b/tests/Frontend/Spss/Conformance/SpssFrontend02Test.php @@ -105,7 +105,7 @@ public static function supplementCases(): iterable public function testSupplementManifestCoverage(): void { - self::assertCount(43, iterator_to_array(self::supplementCases())); + self::assertCount(44, iterator_to_array(self::supplementCases())); } public function testOfficial03ManifestCoverage(): void diff --git a/tests/Integration/OfficialSpssConformanceManifestTest.php b/tests/Integration/OfficialSpssConformanceManifestTest.php index d8ced4c..e079fb1 100644 --- a/tests/Integration/OfficialSpssConformanceManifestTest.php +++ b/tests/Integration/OfficialSpssConformanceManifestTest.php @@ -417,8 +417,7 @@ private function assertCanonicalExpectation(PDO $pdo, string $datasetName, strin 'weight_variable' => self::assertSame(1, $count('SELECT COUNT(*) FROM dataset_weight_variable WHERE dataset_id = ?')), 'variable_labels' => self::assertGreaterThan(0, $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND variable_label IS NOT NULL')), 'print_write_formats' => self::assertSame($count('SELECT COUNT(*) FROM variable WHERE dataset_id = ?'), $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND print_format_family IS NOT NULL AND write_format_family IS NOT NULL')), - // An unknown measurement level is stored as NULL (Conformance Supplement 0.6). - 'measurement_level' => self::assertGreaterThan(0, $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND measurement_level IS NOT NULL')), + 'measurement_level' => self::assertSame($count('SELECT COUNT(*) FROM variable WHERE dataset_id = ?'), $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND measurement_level IS NOT NULL')), 'variable_role' => self::assertSame($count('SELECT COUNT(*) FROM variable WHERE dataset_id = ?'), $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND variable_role IS NOT NULL')), 'display_width' => self::assertSame($count('SELECT COUNT(*) FROM variable WHERE dataset_id = ?'), $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND display_width IS NOT NULL')), 'display_alignment' => self::assertSame($count('SELECT COUNT(*) FROM variable WHERE dataset_id = ?'), $count('SELECT COUNT(*) FROM variable WHERE dataset_id = ? AND display_alignment IS NOT NULL')), diff --git a/tests/Transformation/Conformance/ManifestInventoryTest.php b/tests/Transformation/Conformance/ManifestInventoryTest.php index ae12303..c83ab44 100644 --- a/tests/Transformation/Conformance/ManifestInventoryTest.php +++ b/tests/Transformation/Conformance/ManifestInventoryTest.php @@ -20,7 +20,7 @@ public function testPinnedTransformationManifestInventory(): void public function testPinnedSupplementManifestInventory(): void { - self::assertCount(15, SpecificationManifest::load('conformance/spss-syntax-frontend-0.1-supplement-1.json')['cases']); + self::assertCount(16, SpecificationManifest::load('conformance/spss-syntax-frontend-0.1-supplement-1.json')['cases']); self::assertCount(14, SpecificationManifest::load('conformance/spss-syntax-frontend-0.2-supplement-1.json')['cases']); self::assertCount(14, SpecificationManifest::load('conformance/spss-syntax-frontend-0.3-supplement-1.json')['cases']); self::assertCount(2, SpecificationManifest::load('conformance/transformation-plan-0.1-supplement-1.json')['cases']); From 591ba6530e39695a719bc7b025ec921e56e41483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B5nis=20Ormisson?= Date: Tue, 1 Dec 2026 15:27:55 +0200 Subject: [PATCH 5/7] Pin specification v0.6.0 --- .github/workflows/ci.yml | 10 +++++----- README.md | 6 +++--- docs/transformations.md | 5 ++++- src/Core/CapabilityDeclaration.php | 4 ++-- tests/Core/CapabilityDeclarationTest.php | 4 ++-- tests/Release/SpecificationPinTest.php | 5 +++-- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5446f12..11f4e8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: uses: actions/checkout@v7 with: repository: OpenStatSpec/specification - ref: 864e84479f554b8ee250ffed44c4dfb963750d4a + ref: d76121ec343cf9614fb8ad2f8cc50f72ee29966e path: openstatspec-specification - uses: shivammathur/setup-php@v2 with: @@ -63,7 +63,7 @@ jobs: uses: actions/checkout@v7 with: repository: OpenStatSpec/specification - ref: 864e84479f554b8ee250ffed44c4dfb963750d4a + ref: d76121ec343cf9614fb8ad2f8cc50f72ee29966e path: openstatspec-specification - uses: shivammathur/setup-php@v2 with: @@ -110,7 +110,7 @@ jobs: uses: actions/checkout@v7 with: repository: OpenStatSpec/specification - ref: 864e84479f554b8ee250ffed44c4dfb963750d4a + ref: d76121ec343cf9614fb8ad2f8cc50f72ee29966e path: openstatspec-specification - uses: shivammathur/setup-php@v2 with: @@ -156,7 +156,7 @@ jobs: uses: actions/checkout@v7 with: repository: OpenStatSpec/specification - ref: 864e84479f554b8ee250ffed44c4dfb963750d4a + ref: d76121ec343cf9614fb8ad2f8cc50f72ee29966e path: openstatspec-specification - uses: shivammathur/setup-php@v2 with: @@ -206,7 +206,7 @@ jobs: uses: actions/checkout@v7 with: repository: OpenStatSpec/specification - ref: 864e84479f554b8ee250ffed44c4dfb963750d4a + ref: d76121ec343cf9614fb8ad2f8cc50f72ee29966e path: openstatspec-specification - uses: shivammathur/setup-php@v2 with: diff --git a/README.md b/README.md index a54302c..d666bc9 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ It imports an unencrypted SPSS `.sav` or `.zsav` dataset into a relational datab ## Status -PHP v0.8.1 targets released OpenStatSpec specification `v0.5.0` at immutable -commit `864e84479f554b8ee250ffed44c4dfb963750d4a` +PHP v0.9.0 targets released OpenStatSpec specification `v0.6.0` at immutable +commit `d76121ec343cf9614fb8ad2f8cc50f72ee29966e` (`specification_status: released`). Composer derives the package version from its Git tag; it is independent of the specification version. @@ -260,7 +260,7 @@ Run the local gate before committing: ```bash composer install -# Checkout specification v0.5.0 at 864e84479f554b8ee250ffed44c4dfb963750d4a first. +# Checkout specification v0.6.0 at d76121ec343cf9614fb8ad2f8cc50f72ee29966e first. OPENSTATSPEC_SPECIFICATION_DIR=/path/to/exact-specification-checkout composer check ``` diff --git a/docs/transformations.md b/docs/transformations.md index 6824997..b9f1878 100644 --- a/docs/transformations.md +++ b/docs/transformations.md @@ -184,10 +184,13 @@ composer check They cover all 4 Plan 0.1, 26 Plan 0.2, 44 Frontend 0.2, 6 In-Place 0.1, and 11 In-Place 0.2 manifest cases, plus all 90 effective Frontend 0.3 cases (35 declared plus inherited cases minus the two comment supersessions). +They also run the v0.6.0 supplement manifests: 43 Frontend cases (the Frontend +0.1 boundary case is skipped, as PHP does not claim Frontend 0.1), 2 + 2 Plan, +1 In-Place 0.1 and 9 SAV/ZSAV fixtures. Frontend checks compare source/plan hashes, exact inherited plans, diagnostics and declared metadata preservation. Use `OPENSTATSPEC_SPECIFICATION_DIR=/tmp/openstatspec-alignment-spec` for the -alignment checkout at unchanged commit `864e84479f554b8ee250ffed44c4dfb963750d4a`. +alignment checkout at commit `d76121ec343cf9614fb8ad2f8cc50f72ee29966e`. The public Frontend 0.3 → native SQLite apply regression checks UNKNOWN, metadata, provenance and unchanged dataset/table identity without extra data artifacts or history. All 20 jobs in the diff --git a/src/Core/CapabilityDeclaration.php b/src/Core/CapabilityDeclaration.php index 825cf05..bd7cb6e 100644 --- a/src/Core/CapabilityDeclaration.php +++ b/src/Core/CapabilityDeclaration.php @@ -19,8 +19,8 @@ final readonly class CapabilityDeclaration implements JsonSerializable { public const SPECIFICATION_STATUS = 'released'; - public const SPECIFICATION_RELEASE = 'v0.5.0'; - public const SPECIFICATION_COMMIT = '864e84479f554b8ee250ffed44c4dfb963750d4a'; + public const SPECIFICATION_RELEASE = 'v0.6.0'; + public const SPECIFICATION_COMMIT = 'd76121ec343cf9614fb8ad2f8cc50f72ee29966e'; private Connection $connection; diff --git a/tests/Core/CapabilityDeclarationTest.php b/tests/Core/CapabilityDeclarationTest.php index 5c19b50..a931494 100644 --- a/tests/Core/CapabilityDeclarationTest.php +++ b/tests/Core/CapabilityDeclarationTest.php @@ -17,9 +17,9 @@ public function testDeclarationIsMachineReadableAndIncludesEveryProfileLimit(): $declaration = (new CapabilityDeclaration($pdo, new PhpSpssEngine()))->toArray(); self::assertSame('openstatspec-database-io-v1', $declaration['database_io_policy']); self::assertSame('released', $declaration['specification_status']); - self::assertSame('v0.5.0', $declaration['specification_release']); + self::assertSame('v0.6.0', $declaration['specification_release']); self::assertSame(CapabilityDeclaration::SPECIFICATION_RELEASE, $declaration['specification_release']); - self::assertSame('864e84479f554b8ee250ffed44c4dfb963750d4a', $declaration['specification_commit']); + self::assertSame('d76121ec343cf9614fb8ad2f8cc50f72ee29966e', $declaration['specification_commit']); self::assertSame(CapabilityDeclaration::SPECIFICATION_COMMIT, $declaration['specification_commit']); self::assertMatchesRegularExpression('/^[0-9a-f]{40}$/', $declaration['specification_commit']); self::assertSame(['import', 'export', 'semantic_round_trip'], $declaration['directions']); diff --git a/tests/Release/SpecificationPinTest.php b/tests/Release/SpecificationPinTest.php index e4cfe15..06745bd 100644 --- a/tests/Release/SpecificationPinTest.php +++ b/tests/Release/SpecificationPinTest.php @@ -12,9 +12,9 @@ final class SpecificationPinTest extends TestCase { public function testEverySpecificationCheckoutUsesTheReleasedSpecificationCommit(): void { - self::assertSame('v0.5.0', CapabilityDeclaration::SPECIFICATION_RELEASE); + self::assertSame('v0.6.0', CapabilityDeclaration::SPECIFICATION_RELEASE); self::assertSame( - '864e84479f554b8ee250ffed44c4dfb963750d4a', + 'd76121ec343cf9614fb8ad2f8cc50f72ee29966e', CapabilityDeclaration::SPECIFICATION_COMMIT, ); $workflowFiles = glob(dirname(__DIR__, 2) . '/.github/workflows/*.{yml,yaml}', GLOB_BRACE); @@ -68,6 +68,7 @@ public function testEverySpecificationCheckoutUsesTheReleasedSpecificationCommit 'conformance/spss-syntax-frontend-0.2.json', 'conformance/in-place-transformation-0.1.json', 'conformance/in-place-transformation-0.2.json', + 'docs/conformance-supplement-0.6.md', ] as $relative) { self::assertFileExists(SpecificationManifest::path($relative)); } From e711fd96de8f221c3e0ee165f46aab7ee60d3cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B5nis=20Ormisson?= Date: Tue, 1 Dec 2026 17:17:35 +0200 Subject: [PATCH 6/7] Compare 0.9.0 with 0.8.4 in the changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fad3cfd..33493fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -269,7 +269,8 @@ ownership checks are retained; this release requires no new migration. specification v0.1.0 at commit `d287c2cde9ade71f04e27dd012caec876901aed5`. [Unreleased]: https://github.com/OpenStatSpec/php/compare/v0.9.0...HEAD -[0.9.0]: https://github.com/OpenStatSpec/php/compare/v0.8.3...v0.9.0 +[0.9.0]: https://github.com/OpenStatSpec/php/compare/v0.8.4...v0.9.0 +[0.8.4]: https://github.com/OpenStatSpec/php/compare/v0.8.3...v0.8.4 [0.8.1]: https://github.com/OpenStatSpec/php/compare/v0.8.0...v0.8.1 [0.8.0]: https://github.com/OpenStatSpec/php/compare/v0.7.1...v0.8.0 [0.7.1]: https://github.com/OpenStatSpec/php/compare/v0.7.0...v0.7.1 From f7d8c34173f86bc7f687667f1e7ff5a99aa0a4b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B5nis=20Ormisson?= Date: Tue, 1 Dec 2026 17:21:06 +0200 Subject: [PATCH 7/7] Link the 0.8.2 and 0.8.3 changelog entries --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33493fb..8c94afb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -271,6 +271,8 @@ ownership checks are retained; this release requires no new migration. [Unreleased]: https://github.com/OpenStatSpec/php/compare/v0.9.0...HEAD [0.9.0]: https://github.com/OpenStatSpec/php/compare/v0.8.4...v0.9.0 [0.8.4]: https://github.com/OpenStatSpec/php/compare/v0.8.3...v0.8.4 +[0.8.3]: https://github.com/OpenStatSpec/php/compare/v0.8.2...v0.8.3 +[0.8.2]: https://github.com/OpenStatSpec/php/compare/v0.8.1...v0.8.2 [0.8.1]: https://github.com/OpenStatSpec/php/compare/v0.8.0...v0.8.1 [0.8.0]: https://github.com/OpenStatSpec/php/compare/v0.7.1...v0.8.0 [0.7.1]: https://github.com/OpenStatSpec/php/compare/v0.7.0...v0.7.1