From e0e377e9ba192d49c4b65f1cb9f6bbbe12703c96 Mon Sep 17 00:00:00 2001 From: grandpig Date: Mon, 3 Aug 2026 18:44:34 +0800 Subject: [PATCH] scripts: validate the first Comments-URI entry Signed-off-by: grandpig --- .github/workflows/github-action-checks.yml | 1 + scripts/buildtable.pl | 2 +- scripts/t/buildtable-comments-uri.t | 72 ++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 scripts/t/buildtable-comments-uri.t diff --git a/.github/workflows/github-action-checks.yml b/.github/workflows/github-action-checks.yml index c236e275ad..447efac1d2 100644 --- a/.github/workflows/github-action-checks.yml +++ b/.github/workflows/github-action-checks.yml @@ -11,6 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 + - run: prove scripts/t/*.t - run: scripts/buildtable.pl >/tmp/table.mediawiki || exit 1 Diff-Checks: name: "Diff Checks (fails until number assignment)" diff --git a/scripts/buildtable.pl b/scripts/buildtable.pl index 3f5ba6a5ba..c230c381ba 100755 --- a/scripts/buildtable.pl +++ b/scripts/buildtable.pl @@ -197,7 +197,7 @@ die "Unacceptable license $val in $fn" unless exists $AcceptableLicenses{$val} or ($val eq 'PD' and exists $GrandfatheredPD{$bipnum}) or ($val eq 'CC-BY-SA-4.0' and exists $GrandfatheredCCBySA{$bipnum}); } } elsif ($field eq 'Comments-URI') { - if ($found{'Comments-URI'}) { + if (not $found{'Comments-URI'}) { my $first_comments_uri = sprintf('https://github.com/bitcoin/bips/wiki/Comments:BIP-%04d', $bipnum); die "First Comments-URI must be exactly \"$first_comments_uri\" in $fn" unless $val eq $first_comments_uri; } diff --git a/scripts/t/buildtable-comments-uri.t b/scripts/t/buildtable-comments-uri.t new file mode 100644 index 0000000000..837a5c8191 --- /dev/null +++ b/scripts/t/buildtable-comments-uri.t @@ -0,0 +1,72 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use File::Spec; +use File::Temp qw(tempdir); +use FindBin; +use Test::More; + +my $buildtable = File::Spec->catfile($FindBin::Bin, '..', 'buildtable.pl'); + +sub run_buildtable { + my (@comments_uris) = @_; + my $dir = tempdir(CLEANUP => 1); + my $bip = File::Spec->catfile($dir, 'bip-0001.mediawiki'); + my $stdout = File::Spec->catfile($dir, 'stdout'); + my $stderr = File::Spec->catfile($dir, 'stderr'); + + open my $BIP, '>', $bip or die "Could not create $bip: $!"; + print {$BIP} "
\n";
+	print {$BIP} "  BIP: 1\n";
+	print {$BIP} "  Title: Test BIP\n";
+	print {$BIP} "  Authors: Test Author \n";
+	print {$BIP} "  Comments-URI: $comments_uris[0]\n";
+	for my $uri (@comments_uris[1 .. $#comments_uris]) {
+		print {$BIP} ' ' x (4 + length('Comments-URI')), "$uri\n";
+	}
+	print {$BIP} "  Status: Draft\n";
+	print {$BIP} "  Type: Process\n";
+	print {$BIP} "  Assigned: 2026-08-03\n";
+	print {$BIP} "
\n"; + close $BIP or die "Could not close $bip: $!"; + + my $pid = fork // die "Could not fork: $!"; + if ($pid == 0) { + chdir $dir or die "Could not chdir to $dir: $!"; + open STDOUT, '>', $stdout or die "Could not open $stdout: $!"; + open STDERR, '>', $stderr or die "Could not open $stderr: $!"; + exec $^X, $buildtable; + die "Could not execute $buildtable: $!"; + } + waitpid $pid, 0; + my $exit_code = $? >> 8; + + open my $ERRORS, '<', $stderr or die "Could not open $stderr: $!"; + my $errors = do { local $/; <$ERRORS> }; + close $ERRORS; + + return ($exit_code, $errors); +} + +my $wiki_uri = 'https://github.com/bitcoin/bips/wiki/Comments:BIP-0001'; + +{ + my ($exit_code, $errors) = run_buildtable($wiki_uri); + is($exit_code, 0, 'accepts the standard Comments wiki URI'); + is($errors, '', 'does not report an error for the standard Comments wiki URI'); +} + +{ + my ($exit_code, $errors) = run_buildtable('https://example.com/wrong'); + isnt($exit_code, 0, 'rejects a nonstandard first Comments-URI'); + like($errors, qr/First Comments-URI must be exactly/, 'reports the invalid first Comments-URI'); +} + +{ + my ($exit_code, $errors) = run_buildtable($wiki_uri, 'https://example.com/discussion'); + is($exit_code, 0, 'accepts an additional external discussion URI'); + is($errors, '', 'does not report an error for an additional discussion URI'); +} + +done_testing();