Skip to content

Conversation

Copy link

Copilot AI commented Jan 21, 2026

Adds Yrs v0.21 (Rust CRDT implementation) to the WASM module, establishing infrastructure for future collaborative editing features.

Changes

Rust/WASM Module

  • Added yrs = "0.21" dependency with wasm-opt = false to avoid binaryen download issues
  • Created verify_yrs() function that instantiates a Yrs document to validate the integration:
    #[wasm_bindgen]
    pub fn verify_yrs() -> String {
        let _doc = Doc::new();
        "Yrs CRDT library loaded successfully!".to_string()
    }
  • Added 3 tests (2 unit + 1 WASM-specific)

TypeScript Integration

  • Imported verify_yrs in main.ts and called on plugin load (logs to console)
  • Added "Test WASM: Verify Yrs" command to command palette for manual verification
  • Created test/unit/wasm-yrs-integration.test.ts with 4 integration tests

Impact

  • Adds ~97KB to WASM bundle
  • Zero breaking changes to existing functionality
  • All tests pass (6 Rust + 11 TypeScript)
  • CodeQL scan: 0 vulnerabilities

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • rustwasm.github.io
    • Triggering command: /usr/bin/curl curl REDACTED -sSf -L/tmp/rustc91vGwg/raw-dylibs lib/�� lib/rustlib/x86_/home/REDACTED/work/ObsidianSyncWASM/ObsidianSyncWASM/wasm/target/debug/build/thissh lib/rustlib/x86_-Wl,--as-needed bin/rustc lib/rustlib/x86_/home/REDACTED/.rustup/toolchains/stable-x86_64-REDACTED-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/bin/gcc-ld/ld.lld d_script_build.7-plugin sidian_sync_wasm.so bin/rustc lib/�� lib/rustlib/x86_--build-id 6_64-REDACTED-linux-gnu/lib lib/rustlib/x86_64-REDACTED-linux-gnu/bin/rust-lld b2a256.rlib ipt_build.bb9c09-c ipt_build.bb9c09node install.js lib/rustlib/x86_64-REDACTED-linux-gnu/bin/rust-lld (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Overview

Add the Yrs CRDT library to the WASM module and verify it compiles correctly. This establishes the foundation for collaborative editing features.

Changes Required

1. Update wasm/Cargo.toml

Add Yrs dependency:

yrs = "0.21"

2. Update wasm/src/lib.rs

Add Yrs import:

use yrs::Doc;

Add new function to verify Yrs works:

/// Verify that Yrs CRDT library compiles and can be instantiated in WASM
/// 
/// This function creates a basic Yrs document to confirm the dependency works.
/// Yrs is a Rust port of Yjs, providing Conflict-free Replicated Data Types (CRDTs)
/// for building collaborative applications.
/// 
/// # Returns
/// A success message if Yrs can be initialized
#[wasm_bindgen]
pub fn verify_yrs() -> String {
    // Create a new Yrs document - this proves the library is compiled correctly
    let _doc = Doc::new();
    
    "Yrs CRDT library loaded successfully!".to_string()
}

Add Rust unit tests:

#[test]
fn test_verify_yrs() {
    let result = verify_yrs();
    assert!(result.contains("Yrs"));
    assert!(result.contains("successfully"));
}

#[test]
fn test_verify_yrs_creates_doc() {
    // Verify that calling verify_yrs doesn't panic
    // and that Yrs Doc can be created
    let result = verify_yrs();
    assert!(!result.is_empty());
}

Add WASM-specific test:

#[wasm_bindgen_test]
fn test_verify_yrs_wasm() {
    let result = verify_yrs();
    assert!(result.contains("successfully"));
}

3. Create test/unit/wasm-yrs-integration.test.ts

Add TypeScript integration tests:

/**
 * Integration tests for Yrs CRDT WASM functionality
 */

import { describe, it, expect, vi, beforeEach } from 'vitest';

// Mock the WASM module
vi.mock('../../wasm/pkg/obsidian_sync_wasm.js', () => ({
	default: vi.fn(async () => {}), // init function
	greet: vi.fn((name: string) => `Hello, ${name}!`),
	compute_hash: vi.fn((input: string) => 12345),
	verify_yrs: vi.fn(() => 'Yrs CRDT library loaded successfully!'),
}));

describe('WASM Yrs Integration', () => {
	let verify_yrs: any;

	beforeEach(async () => {
		// Import after mock is set up
		const wasmModule = await import('../../wasm/pkg/obsidian_sync_wasm.js');
		verify_yrs = wasmModule.verify_yrs;
	});

	it('should verify Yrs loads successfully', () => {
		const result = verify_yrs();
		
		expect(result).toBeDefined();
		expect(typeof result).toBe('string');
		expect(result).toContain('Yrs');
	});

	it('should return a success message', () => {
		const result = verify_yrs();
		
		expect(result).toContain('successfully');
	});

	it('should not throw when called', () => {
		expect(() => verify_yrs()).not.toThrow();
	});

	it('should be callable multiple times', () => {
		const result1 = verify_yrs();
		const result2 = verify_yrs();
		
		expect(result1).toBe(result2);
		expect(verify_yrs).toHaveBeenCalledTimes(2);
	});
});

4. Update main.ts

Add verify_yrs to imports:

import init, { greet, compute_hash, verify_yrs } from './wasm/pkg/obsidian_sync_wasm.js';

Add Yrs verification after WASM initialization:

// Initialize WASM with the binary data (using new API format)
await init({ module_or_path: wasmBytes });
this.wasmInitialized = true;
console.log('WASM module initialized successfully from:', wasmPath);

// Verify Yrs is loaded
const yrsStatus = verify_yrs();
console.log('Yrs verification:', yrsStatus);

Add new command to test Yrs:

// Test command to verify Yrs CRDT library
this.addCommand({
	id: 'test-wasm-yrs',
	name: 'Test WASM: Verify Yrs',
	callback: () => {
		if (!this.wasmInitialized) {
			new Notice('WASM module not initialized');
			return;
		}
		const status = verify_yrs();
		new Notice(status);
		console.log('Yrs verification:', status);
	}
});

Acceptance Criteria

  • yrs = "0.21" added to wasm/Cargo.toml dependencies
  • use yrs::Doc; added to wasm/src/lib.rs
  • verify_yrs() function created and exported via #[wasm_bindgen]
  • Rust unit tests added and passing (cargo test)
  • WASM-specific tests added
  • TypeScript integration test file created
  • main.ts updated to import and use verify_yrs()
  • New command "Test WASM: Verify Yrs" added to command palette
  • CI/CD passes (Rust tests + TypeScript tests + build)
  • Console logs "Yrs verification: Yrs CRDT library loaded successfully!" on plugin load

Testing Instructions

Local Testing

# Build WASM with Yrs
npm run wasm

# Run Rust tests
npm run test:rust

# Run TypeScript tests
npm test

# Run all tests
npm run test:all

# Build full plugin
npm run build

Manual Testing in Obsidian

  1. Load the plugin in Obsidian
  2. Open Developer Console (Ctrl+Shift+I / Cmd+Option+I)
  3. Look for: "Yrs verification: Yrs CRDT library loaded successfully!"
  4. Open Command Palette (Ctrl/Cmd+P)
  5. Run "Test WASM: Verify Yrs" command
  6. Should see notice: "Yrs CRDT library loaded success...

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 21, 2026 16:09
Co-authored-by: TWDickson <3435304+TWDickson@users.noreply.github.com>
Co-authored-by: TWDickson <3435304+TWDickson@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Yrs CRDT library to WASM module and verify compilation feat(WASM): Integrate Yrs CRDT library for collaborative editing foundation Jan 21, 2026
Copilot AI requested a review from TWDickson January 21, 2026 16:15
@TWDickson TWDickson marked this pull request as ready for review January 21, 2026 16:17
@TWDickson
Copy link
Owner

Closing in favor of #45 which includes all these changes plus cross-platform
workflow improvements (Windows junction support, Node.js scripts, copy mode fallback).

@TWDickson TWDickson closed this Jan 23, 2026
@TWDickson TWDickson deleted the copilot/add-yrs-crdt-to-wasm branch January 23, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants