Pharo test defects

Package: Sagan (ba-st/Sagan, row 100)

State
Fixed (package repair)
Defect in
see the record
Tests
0
Fix
ba-st-sagan.st
Upstream repository
ba-st/Sagan

The record is the text of the repair. The Results table is the last run of the row.

Record

Test

Load the package into a Pharo 14 image (build 791) with the load expression of the test run, file in the fixes file of the row if there is one, and run the test classes of the package.

"row 100"
Metacello new baseline: 'Sagan'; repository: 'github://ba-st/Sagan:release-candidate/source'; onConflict: [:e | e useIncoming]; load: #('Tests').

Results

Last result of the package run (stock Cog and iospharo on the same image).

RowLabelLoadStock Cogiospharo VM
100ba-st-saganoktests=133 P=133 F=0 E=0 S=0 T=0 X=0tests=133 P=133 F=0 E=0 S=0 T=0 X=0

Fix

Fixes file (filed in after the load): ba-st-sagan.st (download)
"ba-st-sagan (ba-st/Sagan, Sagan-RDBMS-Tests): entries, round 2.

1. The package has no text reader for SQLite on Pharo 14.  The text of a
   result column is read with SQLite3PreparedStatement>>stringAt:, and that
   method sends stringFrom:at: to SQLite3Library.  The dependency Pharo-SQLite3
   defines stringFrom:at: only in the version packages SQLite3-Pharo8 and
   SQLite3-Pharo9, and the baseline of the dependency loads SQLite3-Pharo9 for
   Pharo 9 to 13 only.  On Pharo 14 no package defines stringFrom:at:, and
   each read of a text column ends with MessageNotUnderstood.  The entry adds
   the method with the body of SQLite3-Pharo9.  This is the first cause of the
   errors of the RDBMS tests.  The other errors follow from it: the read stops
   in the middle of a SELECT, the statement stays active, an active statement
   keeps a read lock on the file test.db, and the DROP TABLE of the tearDown
   fails with 'SQLite3Busy: database is locked' and hides the first error.
   The test that ran next found a table that the tearDown did not drop
   ('table ... already exists') or no table.

2. The RDBMS tests use PostgreSQL.  The test class
   SingleSessionRDMBSRepositoryTest chooses its database login when the class
   initializes: the environment variable RDBMS names the database, and without
   the variable the login is PostgreSQL on 127.0.0.1:5432 (user postgres,
   password secret, database test, SSL).  The machine has no PostgreSQL, so the
   login of each test fails with ConnectionClosed.  The package has a login for
   SQLite3 in the same class (sqlite3Login), and the CI of the package runs the
   same tests with RDBMS=SQLite3 (.github/workflows/SQLite3-Integration-Tests.yml).
   The entries make SQLite3 the default login, which is what the CI does with
   the variable.  A variable RDBMS that is set still wins.  The login is built
   at each call, because the SQLite login names the directory of the running
   image, and the image that runs the tests is a copy of the image that was
   prepared.  The last statement runs the class initialization again, so that
   the Glorp default driver of the saved image is SQLite3Driver (the test
   RDBMSSessionProviderTest>>expectedFailingLoginMessage reads that driver
   before it builds any login).

3. The text binding of Pharo-SQLite3.  SQLite3Library>>with:at:putText: passes
   the UTF-8 ByteArray to sqlite3_bind_text with the destructor argument 0
   (SQLITE_STATIC).  SQLite then keeps the pointer and reads the bytes at
   sqlite3_step, but nothing keeps the ByteArray alive after the bind call, and
   a collection can move or reuse the memory before the step.  The repair
   passes SQLITE_TRANSIENT (-1), so SQLite copies the bytes in the call; the
   destructor argument is a 64-bit integer, so that -1 fills the register."

add value: #SQLite3Library value: #stringFrom:at: value: 'fetching' value:
'stringFrom: aStatement at: aColumn

	"Defined by the version packages SQLite3-Pharo8 and SQLite3-Pharo9 of the dependency; the baseline of the dependency does not load one of them on Pharo 14."

	^ self apiColumnText: aStatement atColumn: aColumn'.

fix value: #'SingleSessionRDMBSRepositoryTest class' value: #defaultLogin
	value: [ :source | source includesSubstring: 'postgreSQLLogin' ]
	value:
'defaultLogin

	"SQLite3 in a file of the directory of the image, as the CI of the package does with RDBMS=SQLite3.  No PostgreSQL server runs on this machine."

	<ignoreForCoverage>
	^ self sqlite3Login'.

fix value: #'SingleSessionRDMBSRepositoryTest class' value: #login
	value: [ :source | source includesSubstring: '^ DefaultLogin' ]
	value:
'login

	"Built at each call: the SQLite login names the directory of the running image, and the running image is not the prepared image."

	^ OSEnvironment current
		at: ''RDBMS''
		ifPresent: [ :variable | self loginFor: variable ]
		ifAbsent: [ self defaultLogin ]'.

(Smalltalk globals includesKey: #SingleSessionRDMBSRepositoryTest)
	ifFalse: [ Stdio stdout nextPutAll: 'SKIP SingleSessionRDMBSRepositoryTest class>>initialize (class absent)'; lf; flush ]
	ifTrue: [
		(Smalltalk globals includesKey: #SQLite3Driver)
			ifFalse: [ Stdio stdout nextPutAll: 'SKIP SingleSessionRDMBSRepositoryTest class>>initialize (SQLite3Driver absent)'; lf; flush ]
			ifTrue: [
				(Smalltalk globals at: #SingleSessionRDMBSRepositoryTest) initialize.
				Stdio stdout nextPutAll: 'RAN SingleSessionRDMBSRepositoryTest class>>initialize (SQLite3 login)'; lf; flush ] ].

fix value: #SQLite3Library value: #with:at:putText:
	value: [ :source | source includesSubstring: 'with: 0' ]
	value:
'with: aStatement at: aColumn putText: aString

	| bytes |

	bytes := self pharoStringToUTF8: aString.

	"SQLITE_TRANSIENT (-1): SQLite copies the bytes in this call.  With 0
	(SQLITE_STATIC) SQLite reads the bytes at sqlite3_step, when the garbage
	collector can have moved or reused the memory of the temporary ByteArray."
	^ self
		  apiBindText: aStatement
		  atColumn: aColumn
		  with: bytes
		  with: bytes size
		  with: -1'.

fix value: #SQLite3Library value: #apiBindText:atColumn:with:with:with:
	value: [ :source | source includesSubstring: 'int anotherInteger' ]
	value:
'apiBindText: aStatement atColumn: aColumn with: aString with: anInteger with: anotherInteger
	"int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int, void(*)(void*))
	The last argument is the destructor.  It is a pointer, so it is a 64-bit integer here (SQLITE_TRANSIENT is -1)."

	^ self ffiCall: #(int sqlite3_bind_text (sqlite3_stmt* aStatement, int aColumn, String aString, int anInteger, sqlite3_int64 anotherInteger))'.
Version locks: ba-st-sagan.txt (download)
# Buoy replaces Symbol>>argumentCount of Pharo 14, and the load stops (docs/upstream/package-repairs.md).
Buoy ba-st-buoy

State of 2026-11-20. Made from the test records of the iospharo project (a second Pharo VM). The fixes are proposals for review.