Bug 40989

Summary: t/db_dependent/OAI/Server.t fails on Debian 13
Product: Koha Reporter: Victor Grousset/tuxayo <victor>
Component: Architecture, internals, and plumbingAssignee: Tomás Cohen Arazi (tcohen) <tomascohen>
Status: Pushed to main --- QA Contact: Victor Grousset/tuxayo <victor>
Severity: major    
Priority: P5 - low CC: david, matthias.meusburger, tomascohen
Version: Main   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
This fixes OAI-PMH (tests and request) so that OAI-PMH responses work when Debian 13 (Trixie) is used as the operating system. Trailing slashes are stripped from requestURL for CGI.pm 4.68+ compatibility Technical details: CGI.pm 4.68 (shipped with Debian 13/Trixie) changed the behaviour of self_url() to include a trailing slash when there's no path component. This strips the trailing slash from both the requestURL field in OAI responses and the baseURL field in Identify responses to maintain compatibility across CGI.pm versions.
Version(s) released in:
26.05.00
Circulation function:
Bug Depends on:    
Bug Blocks: 41077    
Attachments: Bug 40989: Fix OAI-PMH tests for CGI.pm 4.68+
Bug 40989: Fix OAI-PMH tests for CGI.pm 4.68+
Bug 40989: Fix OAI-PMH tests for CGI.pm 4.68+

Description Victor Grousset/tuxayo 2025-10-09 21:47:15 UTC
1. KOHA_IMAGE=main-bookworm ktd up
2. prove t/db_dependent/OAI/Server.t
3. pass
4. KOHA_IMAGE=main-trixie ktd up
5. prove t/db_dependent/OAI/Server.t
#    got : 'http://localhost/'
# expect : 'http://localhost'

Severity = major because it makes the CI fail and hides issues even if not as much as Bug 40680.
Comment 1 Tomás Cohen Arazi (tcohen) 2025-12-04 18:20:38 UTC
The tests fail because the returned structures differ. In particular the difference is a trailing slash in the `request: http://localhost` portion of the response.

Debian's updated `CGI` module is the culprit:

To reproduce:
1. Run:
   $ KOHA_IMAGE=main-bookworm ktd --proxy --name bookworm up -d
   $ ktd --name bookworm --wait-ready 120
   $ ktd --name bookworm --shell --run "perl -MCGI -e 'print \"CGI \$CGI::VERSION: \", CGI->new->self_url, \"\n\"'" && ktd --name bookworm down
=> SUCCESS: Prints

```
CGI 4.55: http://localhost
```

2. Run:
   $ KOHA_IMAGE=main-trixie ktd --proxy --name bookworm up -d
   $ ktd --name trixie --wait-ready 120
   $ ktd --name trixie --shell --run "perl -MCGI -e 'print \"CGI \$CGI::VERSION: \", CGI->new->self_url, \"\n\"'" && ktd --name trixie down
=> FAIL: Prints

```
CGI 4.68: http://localhost/
```
Comment 2 Tomás Cohen Arazi (tcohen) 2025-12-04 18:30:47 UTC
Created attachment 190161 [details] [review]
Bug 40989: Fix OAI-PMH tests for CGI.pm 4.68+

CGI.pm 4.68 (shipped with Debian 13/Trixie) changed the behavior of
self_url() to include a trailing slash when there's no path component.
This causes OAI-PMH tests to fail as they expect URLs without trailing
slashes.

This patch strips the trailing slash from both the requestURL field in
OAI responses and the baseURL field in Identify responses to maintain
compatibility across CGI.pm versions.

Test plan:
1. Start a 'trixie' KTD:
   $ KOHA_IMAGE=main-trixie ktd --proxy --name trixie up -d
   $ ktd --name trixie --wait-ready 120
2. Run the tests:
   $ ktd --name trixie --shell
  k$ prove t/db_dependent/OAI/Server.t
=> FAIL: Tests fail!
3. Apply this patch
5. Repeat 2
6. Repeat 1-2 with a 'bookworm' image
=> SUCCESS: Tests pass too!
7. Sign off :-D
Comment 3 David Nind 2025-12-05 06:21:52 UTC
Created attachment 190189 [details] [review]
Bug 40989: Fix OAI-PMH tests for CGI.pm 4.68+

CGI.pm 4.68 (shipped with Debian 13/Trixie) changed the behavior of
self_url() to include a trailing slash when there's no path component.
This causes OAI-PMH tests to fail as they expect URLs without trailing
slashes.

This patch strips the trailing slash from both the requestURL field in
OAI responses and the baseURL field in Identify responses to maintain
compatibility across CGI.pm versions.

Test plan:
1. Start a 'trixie' KTD:
   $ KOHA_IMAGE=main-trixie ktd --proxy --name trixie up -d
   $ ktd --name trixie --wait-ready 120
2. Run the tests:
   $ ktd --name trixie --shell
  k$ prove t/db_dependent/OAI/Server.t
=> FAIL: Tests fail!
3. Apply this patch
5. Repeat 2
6. Repeat 1-2 with a 'bookworm' image
=> SUCCESS: Tests pass too!
7. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Comment 4 Tomás Cohen Arazi (tcohen) 2025-12-05 20:18:04 UTC
Leaving a note for QA review:

* The CGI->self_url() change can be considered an enhancement on CGI. My patch makes sure it doesn't work the way upstream does, but makes it 'not change behavior'. My call was to do it like this because...
* The tests are very large and a refactoring *could* be a pain to support both cases (been told I change too many lines in tests when providing 'a one line fix').
* I don't think that trailing slash is relevant at all in any case
Comment 5 Victor Grousset/tuxayo 2025-12-11 20:11:08 UTC
> refactoring *could* be a pain to support both cases

+1 and if anything to refactor, it would be accommodate the new self_url() output, not both cases. If we can away without wider changes, let's go with that.

--

Not related to fixing the tests but still to the change of self_url(), there are other occurrences of self_url() that on recent OSes I guess should lead to URLs with a double / in the middle.
That shouldn't be a worry right? Unless we have a specific case that could be a concern.

For good measure, I've emailed Matts to know if they think of something when knowing about that self_url() change.

Otherwise, test plan works and code looks good so I think I'll pass QA not later than Monday unless some info comes up.
Comment 6 Victor Grousset/tuxayo 2025-12-12 15:10:25 UTC
Created attachment 190467 [details] [review]
Bug 40989: Fix OAI-PMH tests for CGI.pm 4.68+

CGI.pm 4.68 (shipped with Debian 13/Trixie) changed the behavior of
self_url() to include a trailing slash when there's no path component.
This causes OAI-PMH tests to fail as they expect URLs without trailing
slashes.

This patch strips the trailing slash from both the requestURL field in
OAI responses and the baseURL field in Identify responses to maintain
compatibility across CGI.pm versions.

Test plan:
1. Start a 'trixie' KTD:
   $ KOHA_IMAGE=main-trixie ktd --proxy --name trixie up -d
   $ ktd --name trixie --wait-ready 120
2. Run the tests:
   $ ktd --name trixie --shell
  k$ prove t/db_dependent/OAI/Server.t
=> FAIL: Tests fail!
3. Apply this patch
5. Repeat 2
6. Repeat 1-2 with a 'bookworm' image
=> SUCCESS: Tests pass too!
7. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 7 Victor Grousset/tuxayo 2025-12-12 15:14:36 UTC
Works, makes sense, QA script happy, code looks good, passing QA :)
Comment 8 Victor Grousset/tuxayo 2025-12-12 15:26:48 UTC
Thanks Matts for the quick glance and confirming there seems to be nothing additional to worry about.
Comment 9 Lucas Gass (lukeg) 2025-12-17 20:26:49 UTC
Nice work everyone!

Pushed to main for 26.05