Skip to content

Commit 7346d76

Browse files
first cut
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e351a85 commit 7346d76

16 files changed

Lines changed: 588 additions & 52 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
INSTALL EXTENSION vsql_preview_ping_test;
2+
# ping() returns a positive integer
3+
SELECT vsql_preview_ping_test.ping() > 0 AS ping_positive;
4+
ping_positive
5+
1
6+
# Consecutive calls return strictly increasing values
7+
SELECT vsql_preview_ping_test.ping() < vsql_preview_ping_test.ping() AS ping_increases;
8+
ping_increases
9+
1
10+
UNINSTALL EXTENSION vsql_preview_ping_test;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Test the preview ping capability for vsql_preview_ping_test extension.
2+
# Verifies that the ping() VDF returns an incrementing counter, proving
3+
# the server-side preview capability was populated correctly.
4+
5+
INSTALL EXTENSION vsql_preview_ping_test;
6+
7+
--echo # ping() returns a positive integer
8+
SELECT vsql_preview_ping_test.ping() > 0 AS ping_positive;
9+
10+
--echo # Consecutive calls return strictly increasing values
11+
SELECT vsql_preview_ping_test.ping() < vsql_preview_ping_test.ping() AS ping_increases;
12+
13+
UNINSTALL EXTENSION vsql_preview_ping_test;

villagesql/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,6 @@ IF(NOT WITHOUT_SERVER)
382382

383383
add_custom_target(storage_test_veb ALL)
384384
add_dependencies(storage_test_veb copy_vsql_storage_test_veb)
385+
386+
include(test-extensions/CMakeLists.txt)
385387
ENDIF()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2026 VillageSQL Contributors
2+
//
3+
// This program is free software; you can redistribute it and/or
4+
// modify it under the terms of the GNU General Public License
5+
// as published by the Free Software Foundation; either version 2
6+
// of the License, or (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License, version 2.0, for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with this program; if not, see <https://www.gnu.org/licenses/>.
15+
16+
#ifndef VILLAGESQL_ABI_PREVIEW_PING_H
17+
#define VILLAGESQL_ABI_PREVIEW_PING_H
18+
19+
#include <stdint.h>
20+
21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
25+
// Preview capability: "vsql::ping"
26+
//
27+
// A trivial capability used to exercise and test the preview capability
28+
// registration system. The server provides a single ping() function that
29+
// returns a monotonically incrementing counter.
30+
//
31+
// Capability name: VEF_PREVIEW_PING_NAME
32+
// Capability version: VEF_PREVIEW_PING_VERSION
33+
34+
#define VEF_PREVIEW_PING_NAME "vsql::ping"
35+
#define VEF_PREVIEW_PING_VERSION 1
36+
37+
// Returns a monotonically incrementing counter. Used to verify that the
38+
// capability system is wired up correctly end-to-end.
39+
typedef uint64_t (*vef_ping_fn)(void);
40+
41+
typedef struct {
42+
vef_ping_fn ping;
43+
} vef_preview_ping_t;
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
48+
49+
#endif // VILLAGESQL_ABI_PREVIEW_PING_H

villagesql/sdk/include/villagesql/abi/types.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ typedef enum : unsigned int {
173173
// + get_variable/set_variable/read_keyring/write_keyring
174174
// function pointers in vef_register_arg_t: access to
175175
// MySQL system variables and keyring component.
176+
// + Preview capability system: extensions declare named
177+
// capabilities they require in vef_registration_t;
178+
// the server populates their function pointers before
179+
// vef_register() returns.
180+
// (vef_required_capability_t, required_capabilities,
181+
// required_capability_count in vef_registration_t)
176182
} vef_protocol_t;
177183

178184
// Max length of error messages in caller-provided buffers.
@@ -872,6 +878,21 @@ typedef struct {
872878
};
873879
} vef_status_var_desc_t;
874880

881+
// A single preview capability request in
882+
// vef_registration_t.required_capabilities. The extension sets name, version,
883+
// and the capability pointer. The server then populates the function pointers
884+
// inside the struct pointed to by capability.
885+
typedef struct {
886+
// Capability name, e.g. "vsql::ping". Must remain valid for the lifetime
887+
// of the extension (use a string literal).
888+
const char *name;
889+
// Version of the capability struct the extension was compiled against.
890+
uint32_t version;
891+
// Pointer to the extension's capability struct (e.g. vef_preview_ping_t*).
892+
// The server writes function pointers into this struct.
893+
void *capability;
894+
} vef_required_capability_t;
895+
875896
typedef struct {
876897
// protocol >= VEF_PROTOCOL_1
877898
vef_protocol_t protocol;
@@ -899,6 +920,15 @@ typedef struct {
899920
// protocol >= VEF_PROTOCOL_2
900921
unsigned int status_var_count;
901922
vef_status_var_desc_t **status_vars;
923+
924+
// protocol >= VEF_PROTOCOL_2
925+
// Preview capabilities required by this extension. Each entry names a
926+
// capability the extension needs (e.g. "vsql::ping"). The server populates
927+
// the capability struct pointed to by each entry before vef_register()
928+
// returns. If a capability is unavailable or the version is unsupported,
929+
// its function pointers are left as nullptr.
930+
unsigned int required_capability_count;
931+
const vef_required_capability_t *required_capabilities;
902932
} vef_registration_t;
903933

904934
// The returned objects can be freed when the registration is passed to the

0 commit comments

Comments
 (0)