From 0f5980951edf68360fa549e622ac1b749cf90c9d Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Tue, 5 Aug 2025 14:28:05 +1000 Subject: [PATCH 01/14] maint: add labeler for issues and PRs Test bot has also just been installed, so this serves as a test bot verification also. Relates-to: keymanapp/keyman#559 Test-bot: skip --- .github/multi-labeler.yml | 43 +++++++++++++++++++++++++++++++++++ .github/workflows/labeler.yml | 15 ++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .github/multi-labeler.yml create mode 100644 .github/workflows/labeler.yml diff --git a/.github/multi-labeler.yml b/.github/multi-labeler.yml new file mode 100644 index 0000000..a8d5e25 --- /dev/null +++ b/.github/multi-labeler.yml @@ -0,0 +1,43 @@ +version: v1 + +# This file adds labels based on the scopes in +# keymanapp/keyman:resources/scopes/commit-types.json +# Currently it must be manually kept up to date. Not all labels are added, only +# common ones. The others are commented out. + + +labels: + # + # conventional commit / semantic PR styles + # + + - label: 'auto' + matcher: + title: '^auto(\(|:)' + - label: 'change' + matcher: + title: '^change(\(|:)' + - label: 'chore' + matcher: + title: '^chore(\(|:)' + - label: 'docs' + matcher: + title: '^docs(\(|:)' + - label: 'feat' + matcher: + title: '^feat(\(|:)' + - label: 'fix' + matcher: + title: '^fix(\(|:)' + - label: 'maint' + matcher: + title: '^maint(\(|:)' + - label: 'refactor' + matcher: + title: '^refactor(\(|:)' + - label: 'style' + matcher: + title: '^style(\(|:)' + - label: 'test' + matcher: + title: '^test(\(|:)' diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000..08ccd58 --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,15 @@ +name: "Pull Request Labeler" +on: +- pull_request + +jobs: + triage: + if: github.repository == 'keymanapp/status.keyman.com' + runs-on: ubuntu-latest + steps: + - name: Update labels based on PR title + id: labeler + uses: fuxingloh/multi-labeler@f5bd7323b53b0833c1e4ed8d7b797ae995ef75b4 # v2.0.1 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + config-path: .github/multi-labeler.yml From c5ecf065f9c38ce828d6f1e2f5f2bcd1ddf40445 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Tue, 5 Aug 2025 14:28:05 +1000 Subject: [PATCH 02/14] maint: add labeler for issues and PRs Test bot has also just been installed, so this serves as a test bot verification also. Relates-to: keymanapp/keyman#559 Test-bot: skip --- .github/multi-labeler.yml | 43 +++++++++++++++++++++++++++++++++++ .github/workflows/labeler.yml | 15 ++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .github/multi-labeler.yml create mode 100644 .github/workflows/labeler.yml diff --git a/.github/multi-labeler.yml b/.github/multi-labeler.yml new file mode 100644 index 0000000..a8d5e25 --- /dev/null +++ b/.github/multi-labeler.yml @@ -0,0 +1,43 @@ +version: v1 + +# This file adds labels based on the scopes in +# keymanapp/keyman:resources/scopes/commit-types.json +# Currently it must be manually kept up to date. Not all labels are added, only +# common ones. The others are commented out. + + +labels: + # + # conventional commit / semantic PR styles + # + + - label: 'auto' + matcher: + title: '^auto(\(|:)' + - label: 'change' + matcher: + title: '^change(\(|:)' + - label: 'chore' + matcher: + title: '^chore(\(|:)' + - label: 'docs' + matcher: + title: '^docs(\(|:)' + - label: 'feat' + matcher: + title: '^feat(\(|:)' + - label: 'fix' + matcher: + title: '^fix(\(|:)' + - label: 'maint' + matcher: + title: '^maint(\(|:)' + - label: 'refactor' + matcher: + title: '^refactor(\(|:)' + - label: 'style' + matcher: + title: '^style(\(|:)' + - label: 'test' + matcher: + title: '^test(\(|:)' diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000..08ccd58 --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,15 @@ +name: "Pull Request Labeler" +on: +- pull_request + +jobs: + triage: + if: github.repository == 'keymanapp/status.keyman.com' + runs-on: ubuntu-latest + steps: + - name: Update labels based on PR title + id: labeler + uses: fuxingloh/multi-labeler@f5bd7323b53b0833c1e4ed8d7b797ae995ef75b4 # v2.0.1 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + config-path: .github/multi-labeler.yml From 600a608f2b777daf21328ce05ebd2955e2c2a1c7 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Wed, 6 Aug 2025 11:45:07 +0200 Subject: [PATCH 03/14] Apply suggestion from @darcywong00 Co-authored-by: Darcy Wong --- .github/workflows/labeler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 08ccd58..819e241 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -4,7 +4,7 @@ on: jobs: triage: - if: github.repository == 'keymanapp/status.keyman.com' + if: github.repository == 'keymanapp/api.keyman.com' runs-on: ubuntu-latest steps: - name: Update labels based on PR title From 0dca37f05af7acb322d2b63b18d1ab3d62afa3fb Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 8 Aug 2025 05:23:18 +0200 Subject: [PATCH 04/14] maint: fix repo name --- .github/workflows/labeler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 08ccd58..819e241 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -4,7 +4,7 @@ on: jobs: triage: - if: github.repository == 'keymanapp/status.keyman.com' + if: github.repository == 'keymanapp/api.keyman.com' runs-on: ubuntu-latest steps: - name: Update labels based on PR title From e9b4507c4dabee2b29a6d95b3b738328bd6b8ab1 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 8 Aug 2025 05:50:47 +0200 Subject: [PATCH 05/14] chore: diagnose sql inconsistency (temp) --- tools/db/build/sp_keyboard_search.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/db/build/sp_keyboard_search.sql b/tools/db/build/sp_keyboard_search.sql index 5cc4302..23b4d23 100644 --- a/tools/db/build/sp_keyboard_search.sql +++ b/tools/db/build/sp_keyboard_search.sql @@ -471,7 +471,7 @@ AS v_keyboard_downloads_month kd on temp.keyboard_id = kd.keyboard_id left join v_keyboard_downloads_total kdt on k.keyboard_id = kdt.keyboard_id where - temp.roworder = 1 and + -- temp.roworder = 1 and (k.obsolete = 0 or @prmObsolete = 1) order by k.obsolete ASC, -- obsolete keyboards always last From 404be0dc97180d2765ef465b797acd26ed64a9db Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 8 Aug 2025 06:55:18 +0200 Subject: [PATCH 06/14] chore: debug search result diffs --- tests/Search20Test.php | 13 ++++ tools/db/build/sp_keyboard_search_debug.sql | 67 +++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tools/db/build/sp_keyboard_search_debug.sql diff --git a/tests/Search20Test.php b/tests/Search20Test.php index 261d548..9eae4ab 100644 --- a/tests/Search20Test.php +++ b/tests/Search20Test.php @@ -43,6 +43,19 @@ public function testSimpleSearchResultValidatesAgainstSchema(): void $this->assertTrue(true); } + public function testSimpleSearchResultsDebug() + { + $stmt = $this->mssql->prepare("EXEC sp_keyboard_search_debug 'khmer', 'khmer', null, 1, 1, 10"); + if(!$stmt->execute()) { + $this->assertEquals(false, true, 'stmt->execute'); + } + + $data = $stmt->fetchAll(); + echo json_encode($data); //var_dump($data); + + $this->assertEquals(false, true, 'debugging'); + } + public function testSimpleSearchResultContentsConsistent() { $json = $this->s->GetSearchMatches(null, 'khmer', 1, 1); diff --git a/tools/db/build/sp_keyboard_search_debug.sql b/tools/db/build/sp_keyboard_search_debug.sql new file mode 100644 index 0000000..5130194 --- /dev/null +++ b/tools/db/build/sp_keyboard_search_debug.sql @@ -0,0 +1,67 @@ +-- # +-- # sp_keyboard_search_debug +-- # + +DROP PROCEDURE IF EXISTS sp_keyboard_search_debug; +GO + +CREATE PROCEDURE sp_keyboard_search_debug + @prmSearchText nvarchar(250), + @prmIDSearchText nvarchar(250), -- should be ascii (ideally, id only /[a-z][a-z0-9_]*/) + @prmPlatform nvarchar(32), + @prmObsolete bit, + @prmPageNumber int, + @prmPageSize int +AS +BEGIN + SET NOCOUNT ON; + + declare @tt_langtag tt_keyboard_search_langtag + declare @tt_keyboard tt_keyboard_search_keyboard + + declare @q NVARCHAR(131) = '"'+@prmSearchText+'*"' + declare @likeid NVARCHAR(385) = CASE WHEN @prmIDSearchText='' THEN '' ELSE REPLACE(@prmIDSearchText, '_', '[_]')+'%' END + + declare @weight_langtag INT = 10 + declare @weight_country INT = 1 + declare @weight_script INT = 5 + declare @weight_keyboard INT = 30 + declare @weight_keyboard_id INT = 25 + declare @weight_keyboard_description INT = 5 + declare @weight_factor_exact_match INT = 3 + + -- # + -- # Search across language names, country names and script names + -- # + + insert @tt_langtag select * from f_keyboard_search_langtag_by_language(@prmSearchText, @q, @weight_factor_exact_match, @weight_langtag) + insert @tt_langtag select * from f_keyboard_search_langtag_by_country(@prmSearchText, @q, @weight_factor_exact_match, @weight_country) + insert @tt_langtag select * from f_keyboard_search_langtag_by_script(@prmSearchText, @q, @weight_factor_exact_match, @weight_script) + + -- # + -- # Search across keyboards + -- # + + insert @tt_keyboard select * from f_keyboard_search(@prmSearchText, @q, @prmPlatform, @weight_factor_exact_match, @weight_keyboard) + insert @tt_keyboard select * from f_keyboard_search_by_id(@prmSearchText, @likeid, @prmPlatform, @weight_factor_exact_match, @weight_keyboard_id) + insert @tt_keyboard select * from f_keyboard_search_by_description(@prmSearchText, @q, @prmPlatform, @weight_factor_exact_match, @weight_keyboard_description) + + -- # + -- # Add all langtag, country and script matches to the keyboards temp table, with appropriate weights + -- # + + insert @tt_keyboard select * from f_keyboard_search_keyboards_from_langtags(@prmPlatform, @tt_langtag) + + -- # + -- # Build final list of results; two result sets: summary data and current page result + -- # + + SET NOCOUNT OFF; + + -- select * from f_keyboard_search_statistics(@prmPageSize, @prmPageNumber, @prmObsolete, @tt_keyboard) + -- select * from f_keyboard_search_results(@prmPageSize, @prmPageNumber, @prmObsolete, @tt_keyboard) + select * from @tt_keyboard + select * from @tt_langtag +END +GO + From bc79da79d4bb3397a1815805e1e6004cce712514 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 8 Aug 2025 07:28:08 +0200 Subject: [PATCH 07/14] chore: debug continues --- tests/Search20Test.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/Search20Test.php b/tests/Search20Test.php index 2d100f4..c5a5be8 100644 --- a/tests/Search20Test.php +++ b/tests/Search20Test.php @@ -51,13 +51,22 @@ public function testSimpleSearchResultsDebug() } $data = $stmt->fetchAll(); - echo "---@tt_keyboard---\n"; + echo "\n---@tt_keyboard---\n"; echo json_encode($data); $stmt->nextRowset(); $data = $stmt->fetchAll(); - echo "---@tt_langtag---\n"; + echo "\n---@tt_langtag---\n"; + echo json_encode($data); + + $stmt = $this->mssql->prepare(" select top 10 * from t_langtag_name where name like 'khmer%'"); + if(!$stmt->execute()) { + $this->assertEquals(false, true, 'stmt->execute'); + } + + $data = $stmt->fetchAll(); + echo "\n---t_langtag_name---\n"; echo json_encode($data); $this->assertEquals(false, true, 'debugging'); From 6c4ce6a8b09c7558dde375accf6021120e6475e0 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 8 Aug 2025 07:41:09 +0200 Subject: [PATCH 08/14] chore: debug cont --- tests/Search20Test.php | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/Search20Test.php b/tests/Search20Test.php index c5a5be8..c18dada 100644 --- a/tests/Search20Test.php +++ b/tests/Search20Test.php @@ -43,32 +43,31 @@ public function testSimpleSearchResultValidatesAgainstSchema(): void $this->assertTrue(true); } - public function testSimpleSearchResultsDebug() - { - $stmt = $this->mssql->prepare("EXEC sp_keyboard_search_debug 'khmer', 'khmer', null, 1, 1, 10"); + private function __debug($sql, $rowsets) { + $stmt = $this->mssql->prepare($sql); if(!$stmt->execute()) { $this->assertEquals(false, true, 'stmt->execute'); } + echo "\nSQL: $sql\n"; $data = $stmt->fetchAll(); - echo "\n---@tt_keyboard---\n"; - echo json_encode($data); - - $stmt->nextRowset(); - - $data = $stmt->fetchAll(); - echo "\n---@tt_langtag---\n"; echo json_encode($data); - - $stmt = $this->mssql->prepare(" select top 10 * from t_langtag_name where name like 'khmer%'"); - if(!$stmt->execute()) { - $this->assertEquals(false, true, 'stmt->execute'); + while($rowsets > 1) { + $stmt->nextRowset(); + $data = $stmt->fetchAll(); + echo "\n"; + echo json_encode($data); + $rowsets--; } + echo "\n"; + echo "\n"; + } - $data = $stmt->fetchAll(); - echo "\n---t_langtag_name---\n"; - echo json_encode($data); - + public function testSimpleSearchResultsDebug() + { + $this->__debug("EXEC sp_keyboard_search_debug 'khmer', 'khmer', null, 1, 1, 10", 2); + $this->__debug("select top 10 * from t_langtag_name where name like 'khmer%'", 1); + $this->__debug("select top 10 * from t_langtag_name where CONTAINS(name, 'khmer')", 1); $this->assertEquals(false, true, 'debugging'); } From f409f59cbbd861cf9d411e3be1e5aed790073684 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 8 Aug 2025 07:46:25 +0200 Subject: [PATCH 09/14] chore: debug cont --- tests/Search20Test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Search20Test.php b/tests/Search20Test.php index c18dada..20f4892 100644 --- a/tests/Search20Test.php +++ b/tests/Search20Test.php @@ -68,6 +68,7 @@ public function testSimpleSearchResultsDebug() $this->__debug("EXEC sp_keyboard_search_debug 'khmer', 'khmer', null, 1, 1, 10", 2); $this->__debug("select top 10 * from t_langtag_name where name like 'khmer%'", 1); $this->__debug("select top 10 * from t_langtag_name where CONTAINS(name, 'khmer')", 1); + $this->__debug("select top 10 * from t_keyboard where CONTAINS(name, 'khmer')", 1); $this->assertEquals(false, true, 'debugging'); } From f7398fe92c62799b8047348af1fd782d8ac0a331 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 8 Aug 2025 08:58:29 +0200 Subject: [PATCH 10/14] chore: further debug of ft logs --- build.sh | 8 +++++++- tests/Search20Test.php | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 4191281..f759fe7 100755 --- a/build.sh +++ b/build.sh @@ -38,7 +38,13 @@ function test_docker_container() { # Note: ci.yml replicates these # Run unit tests - docker exec $API_KEYMAN_CONTAINER_DESC sh -c "vendor/bin/phpunit --testdox" + docker exec $API_KEYMAN_CONTAINER_DESC sh -c "vendor/bin/phpunit --testdox" || FAILCODE=$? + + docker exec $API_KEYMAN_DB_CONTAINER_DESC sh -c "cat /var/opt/mssql/log/SQLFT*" + + if [[ $FAILCODE != 0 ]]; then + builder_die "Tests failed with $FAILCODE" + fi # Lint .php files for obvious errors docker exec $API_KEYMAN_CONTAINER_DESC sh -c "find . -name '*.php' | grep -v '/vendor/' | xargs -n 1 -d '\\n' php -l" diff --git a/tests/Search20Test.php b/tests/Search20Test.php index 20f4892..18863c8 100644 --- a/tests/Search20Test.php +++ b/tests/Search20Test.php @@ -65,6 +65,7 @@ private function __debug($sql, $rowsets) { public function testSimpleSearchResultsDebug() { + // $this->__debug("xp_readerrorlog 0, 1, N'Logging SQL Server messages in file'", 1); $this->__debug("EXEC sp_keyboard_search_debug 'khmer', 'khmer', null, 1, 1, 10", 2); $this->__debug("select top 10 * from t_langtag_name where name like 'khmer%'", 1); $this->__debug("select top 10 * from t_langtag_name where CONTAINS(name, 'khmer')", 1); From 090f540b87a63332084e4114a1b63ef2f5415c2e Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 8 Aug 2025 09:06:23 +0200 Subject: [PATCH 11/14] chore: errorlog debug --- build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build.sh b/build.sh index f759fe7..7cadf06 100755 --- a/build.sh +++ b/build.sh @@ -41,6 +41,7 @@ function test_docker_container() { docker exec $API_KEYMAN_CONTAINER_DESC sh -c "vendor/bin/phpunit --testdox" || FAILCODE=$? docker exec $API_KEYMAN_DB_CONTAINER_DESC sh -c "cat /var/opt/mssql/log/SQLFT*" + docker exec $API_KEYMAN_DB_CONTAINER_DESC sh -c "cat /var/opt/mssql/log/errorlog*" if [[ $FAILCODE != 0 ]]; then builder_die "Tests failed with $FAILCODE" From b28b01a5ba9118cdd5bf3aae6e0ff6bd8606aa61 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 8 Aug 2025 09:17:29 +0200 Subject: [PATCH 12/14] chore: test ft indexing complete --- tests/Search20Test.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/Search20Test.php b/tests/Search20Test.php index 18863c8..fc992cd 100644 --- a/tests/Search20Test.php +++ b/tests/Search20Test.php @@ -63,6 +63,27 @@ private function __debug($sql, $rowsets) { echo "\n"; } + public function testSimpleSearchResultsAssessFTComplete() + { + $stmt = $this->mssql->prepare("select * from sys.fulltext_indexes where has_crawl_completed=0"); + if(!$stmt->execute()) { + $this->assertEquals(false, true, 'stmt->execute'); + } + $data = $stmt->fetchAll(); + + while(count($data) > 0) { + echo "FT Indexing not complete, waiting 3 seconds\n"; + echo json_encode($data); + sleep(3); + if(!$stmt->execute()) { + $this->assertEquals(false, true, 'stmt->execute'); + } + $data = $stmt->fetchAll(); + } + + echo "FT Indexing is now complete\n"; + } + public function testSimpleSearchResultsDebug() { // $this->__debug("xp_readerrorlog 0, 1, N'Logging SQL Server messages in file'", 1); @@ -70,6 +91,7 @@ public function testSimpleSearchResultsDebug() $this->__debug("select top 10 * from t_langtag_name where name like 'khmer%'", 1); $this->__debug("select top 10 * from t_langtag_name where CONTAINS(name, 'khmer')", 1); $this->__debug("select top 10 * from t_keyboard where CONTAINS(name, 'khmer')", 1); + $this->assertEquals(false, true, 'debugging'); } From 797876fed193899a86b5c4d3bcd34efb65e6cd9d Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 8 Aug 2025 09:53:11 +0200 Subject: [PATCH 13/14] fix: wait for full text indexing to complete when building database We started to see situations where status checks for new PRs would fail, for example see #290, with hard to parse errors about actual search results mismatching expected results. After digging in, with a lot of logging and debugging, I found that the issue was a race where the test would run before full text indexing had completed. This change delays the completion of the database build until the full text indexing has finished. The full description of my investigation is recorded in #290 for future reference. --- tools/db/build/build.inc.php | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tools/db/build/build.inc.php b/tools/db/build/build.inc.php index c7963d2..7c93a33 100644 --- a/tools/db/build/build.inc.php +++ b/tools/db/build/build.inc.php @@ -82,6 +82,8 @@ function BuildDatabase($DBDataSources, $schema, $do_force) { $this->sqlrun(dirname(__FILE__)."/full-text-indexes.sql", false, false); $this->sqlrun(dirname(__FILE__)."/search-queries.sql"); + $this->waitForFullTextIndexing(); + // Run scripts for all views automatically $scripts = glob(__DIR__ . '/v_*.sql'); foreach($scripts as $script) { @@ -107,6 +109,41 @@ function BuildDatabase($DBDataSources, $schema, $do_force) { return true; } + private function waitForFullTextIndexing() { + $dci = new DatabaseConnectionInfo(); + + try { + $mssql = new PDO( + $dci->getConnectionString(), + $this->schema, + $dci->getPassword(), + [ "CharacterSet" => "UTF-8" ]); + $mssql->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); + $mssql->setAttribute( PDO::SQLSRV_ATTR_DIRECT_QUERY, true); + $mssql->setAttribute( PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_UTF8 ); + } + catch( PDOException $e ) { + die( "Error connecting to SQL Server: " . $e->getMessage() ); + } + + $stmt = $mssql->prepare("select * from sys.fulltext_indexes where has_crawl_completed=0"); + if(!$stmt->execute()) { + die( "Error checking Full Text Indexing status" ); + } + $data = $stmt->fetchAll(); + + while(count($data) > 0) { + echo "Full Text Indexing not complete, waiting 3 seconds\n"; + sleep(3); + if(!$stmt->execute()) { + die( "Error checking Full Text Indexing status" ); + } + $data = $stmt->fetchAll(); + } + + echo "Full Text Indexing is now complete\n"; + } + function buildDBDataSources($data_path, DBDataSources $DBDataSources) { $sql = ''; From 0512ede1a2dda3dca36cdc27b3eaddcc7e7a4eed Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 8 Aug 2025 10:10:38 +0200 Subject: [PATCH 14/14] chore: roll back debugging Keeping in git log for posterity --- build.sh | 9 +-- tests/Search20Test.php | 52 ---------------- tools/db/build/sp_keyboard_search_debug.sql | 67 --------------------- 3 files changed, 1 insertion(+), 127 deletions(-) delete mode 100644 tools/db/build/sp_keyboard_search_debug.sql diff --git a/build.sh b/build.sh index 7cadf06..4191281 100755 --- a/build.sh +++ b/build.sh @@ -38,14 +38,7 @@ function test_docker_container() { # Note: ci.yml replicates these # Run unit tests - docker exec $API_KEYMAN_CONTAINER_DESC sh -c "vendor/bin/phpunit --testdox" || FAILCODE=$? - - docker exec $API_KEYMAN_DB_CONTAINER_DESC sh -c "cat /var/opt/mssql/log/SQLFT*" - docker exec $API_KEYMAN_DB_CONTAINER_DESC sh -c "cat /var/opt/mssql/log/errorlog*" - - if [[ $FAILCODE != 0 ]]; then - builder_die "Tests failed with $FAILCODE" - fi + docker exec $API_KEYMAN_CONTAINER_DESC sh -c "vendor/bin/phpunit --testdox" # Lint .php files for obvious errors docker exec $API_KEYMAN_CONTAINER_DESC sh -c "find . -name '*.php' | grep -v '/vendor/' | xargs -n 1 -d '\\n' php -l" diff --git a/tests/Search20Test.php b/tests/Search20Test.php index fc992cd..261d548 100644 --- a/tests/Search20Test.php +++ b/tests/Search20Test.php @@ -43,58 +43,6 @@ public function testSimpleSearchResultValidatesAgainstSchema(): void $this->assertTrue(true); } - private function __debug($sql, $rowsets) { - $stmt = $this->mssql->prepare($sql); - if(!$stmt->execute()) { - $this->assertEquals(false, true, 'stmt->execute'); - } - - echo "\nSQL: $sql\n"; - $data = $stmt->fetchAll(); - echo json_encode($data); - while($rowsets > 1) { - $stmt->nextRowset(); - $data = $stmt->fetchAll(); - echo "\n"; - echo json_encode($data); - $rowsets--; - } - echo "\n"; - echo "\n"; - } - - public function testSimpleSearchResultsAssessFTComplete() - { - $stmt = $this->mssql->prepare("select * from sys.fulltext_indexes where has_crawl_completed=0"); - if(!$stmt->execute()) { - $this->assertEquals(false, true, 'stmt->execute'); - } - $data = $stmt->fetchAll(); - - while(count($data) > 0) { - echo "FT Indexing not complete, waiting 3 seconds\n"; - echo json_encode($data); - sleep(3); - if(!$stmt->execute()) { - $this->assertEquals(false, true, 'stmt->execute'); - } - $data = $stmt->fetchAll(); - } - - echo "FT Indexing is now complete\n"; - } - - public function testSimpleSearchResultsDebug() - { - // $this->__debug("xp_readerrorlog 0, 1, N'Logging SQL Server messages in file'", 1); - $this->__debug("EXEC sp_keyboard_search_debug 'khmer', 'khmer', null, 1, 1, 10", 2); - $this->__debug("select top 10 * from t_langtag_name where name like 'khmer%'", 1); - $this->__debug("select top 10 * from t_langtag_name where CONTAINS(name, 'khmer')", 1); - $this->__debug("select top 10 * from t_keyboard where CONTAINS(name, 'khmer')", 1); - - $this->assertEquals(false, true, 'debugging'); - } - public function testSimpleSearchResultContentsConsistent() { $json = $this->s->GetSearchMatches(null, 'khmer', 1, 1); diff --git a/tools/db/build/sp_keyboard_search_debug.sql b/tools/db/build/sp_keyboard_search_debug.sql deleted file mode 100644 index 5130194..0000000 --- a/tools/db/build/sp_keyboard_search_debug.sql +++ /dev/null @@ -1,67 +0,0 @@ --- # --- # sp_keyboard_search_debug --- # - -DROP PROCEDURE IF EXISTS sp_keyboard_search_debug; -GO - -CREATE PROCEDURE sp_keyboard_search_debug - @prmSearchText nvarchar(250), - @prmIDSearchText nvarchar(250), -- should be ascii (ideally, id only /[a-z][a-z0-9_]*/) - @prmPlatform nvarchar(32), - @prmObsolete bit, - @prmPageNumber int, - @prmPageSize int -AS -BEGIN - SET NOCOUNT ON; - - declare @tt_langtag tt_keyboard_search_langtag - declare @tt_keyboard tt_keyboard_search_keyboard - - declare @q NVARCHAR(131) = '"'+@prmSearchText+'*"' - declare @likeid NVARCHAR(385) = CASE WHEN @prmIDSearchText='' THEN '' ELSE REPLACE(@prmIDSearchText, '_', '[_]')+'%' END - - declare @weight_langtag INT = 10 - declare @weight_country INT = 1 - declare @weight_script INT = 5 - declare @weight_keyboard INT = 30 - declare @weight_keyboard_id INT = 25 - declare @weight_keyboard_description INT = 5 - declare @weight_factor_exact_match INT = 3 - - -- # - -- # Search across language names, country names and script names - -- # - - insert @tt_langtag select * from f_keyboard_search_langtag_by_language(@prmSearchText, @q, @weight_factor_exact_match, @weight_langtag) - insert @tt_langtag select * from f_keyboard_search_langtag_by_country(@prmSearchText, @q, @weight_factor_exact_match, @weight_country) - insert @tt_langtag select * from f_keyboard_search_langtag_by_script(@prmSearchText, @q, @weight_factor_exact_match, @weight_script) - - -- # - -- # Search across keyboards - -- # - - insert @tt_keyboard select * from f_keyboard_search(@prmSearchText, @q, @prmPlatform, @weight_factor_exact_match, @weight_keyboard) - insert @tt_keyboard select * from f_keyboard_search_by_id(@prmSearchText, @likeid, @prmPlatform, @weight_factor_exact_match, @weight_keyboard_id) - insert @tt_keyboard select * from f_keyboard_search_by_description(@prmSearchText, @q, @prmPlatform, @weight_factor_exact_match, @weight_keyboard_description) - - -- # - -- # Add all langtag, country and script matches to the keyboards temp table, with appropriate weights - -- # - - insert @tt_keyboard select * from f_keyboard_search_keyboards_from_langtags(@prmPlatform, @tt_langtag) - - -- # - -- # Build final list of results; two result sets: summary data and current page result - -- # - - SET NOCOUNT OFF; - - -- select * from f_keyboard_search_statistics(@prmPageSize, @prmPageNumber, @prmObsolete, @tt_keyboard) - -- select * from f_keyboard_search_results(@prmPageSize, @prmPageNumber, @prmObsolete, @tt_keyboard) - select * from @tt_keyboard - select * from @tt_langtag -END -GO -