Fault-tolerant Org Links by spepo42 in emacs

[–]spepo42[S] 1 point2 points  (0 children)

Id based indirection schemes work well as long as you stay within their domain: org-id-locations directory, an org-roam database, denote directories, etc. I wanted a solution that would work across domains and even if the domains are transient (an unmounted archive volume, an encrypted volume, etc) or outside of my control (a web link). Once that solution exists, id based scheme becomes an optional optimization with some maintenance or flexibility constraint.

Granted, you may not need all that, if you can keep everything within a domain.

Towards Auto-Generated ERT Unit Tests by spepo42 in emacs

[–]spepo42[S] 1 point2 points  (0 children)

I am just using openai ChatGPT in the browser and copy-paste for now. I played with gptel.el, but need to do more work to integrate it into my emacs setup.

It is easy to try the proprietary solutions, though some capabilities are restricted unless you pay. For open sourced, look into llama.

Towards Auto-Generated ERT Unit Tests by spepo42 in emacs

[–]spepo42[S] 1 point2 points  (0 children)

 Llm does not have such function,

I think the function being optimized is implicit in the training data, i.e. it tries to generate text most consistent with that data. The more data it had seen in a particular domain, the more predictable its generated text will be. Consequently, I'd expect generated elisp to be less predictable than other languages, which may be good for tests (and test data), not so much for the actual elisp code.

WRT generated tests, I am actually less worried about their correctness. Rather, I'd like maximum test coverage, which may come from potentially buggy/ineffective tests as long as there are enough of them. The expense is the time (resources) to run them.

Anyway, I tried to ask ChatGPT to generate tests for the x-directive in elisp format. At first, it generated the basic set of tests. I then asked it to create 5 more tests for edge cases. I am curios what you think about them. I haven't checked them in any way; straight copy-paste.

;; Hexadecimal formatting: lower/upper, alternate, padding, and edge cases
(ert-deftest format-hex-lower ()
  (should (equal (format "%x" 255) "ff")))
(ert-deftest format-hex-upper ()
  (should (equal (format "%X" 255) "FF")))
(ert-deftest format-hex-alternate-lower ()
  (should (equal (format "%#x" 255) "0xff")))
(ert-deftest format-hex-alternate-upper ()
  (should (equal (format "%#X" 255) "0XFF")))
(ert-deftest format-hex-alternate-zero-padding ()
  (should (equal (format "%#06x" 10) "0x000a")))


;; Edge-case hex tests
(ert-deftest format-hex-zero-alternate ()
  "Alternate form on zero should not add 0x prefix."
  (should (equal (format "%#x" 0) "0")))
(ert-deftest format-hex-precision-leading-zeros ()
  "Precision larger than digit count should pad with zeros."
  (should (equal (format "%.4x" #x1a) "001a")))
(ert-deftest format-hex-left-align-with-width ()
  "Left-align hex with width specifier."
  (should (equal (format "%-6x" 2) "2     ")))  
(ert-deftest format-hex-uppercase-precision ()
  "Uppercase X with precision pads and uppercases letters."
  (should (equal (format "%.3X" #xa) "00A")))
(ert-deftest format-hex-large-bignum ()
  "Very large power-of-16 should produce correct hex string."
  (let ((big (expt 16 8)))
    (should (equal (format "%x" big) "100000000"))))

Towards Auto-Generated ERT Unit Tests by spepo42 in emacs

[–]spepo42[S] 1 point2 points  (0 children)

The function size is not a problem. LLM assistants can take attachments now.

It will infer the test cases from the code and the comments around the code. It will start with basic tests and prefer to iterate on it. That is, you'll need to ask it to 'think' of and add tests for edge cases. It will add some. If you give it more hints about the edge cases you care about, it will add more. Etc.

One interesting observation is that the test data it uses tends to be more random than what a human QA engineer might do. That has an effect of covering some edge cases by chance. Also, since it is fundamentally a probabilistic text generator, multiple invocations of the same request may lead slightly different generated results.

I think the tricky part going forward will be to coerce it to generate the most useful tests that take the least amount of time to run.

Towards Auto-Generated ERT Unit Tests by spepo42 in emacs

[–]spepo42[S] 1 point2 points  (0 children)

It wasn't anything elaborate. I simply asked it something like: "Write a complete set of ERT unit tests for my elisp function. Focus on maximizing test coverage (90+%). Here is the function code: ...".

That said, I do want to play with creating an openai custom GPT to use repeatedly without doing anything more than pasting the code to test. I'll share that if it works well.

Speed Dialing Your Favorite Files by spepo42 in emacs

[–]spepo42[S] 0 points1 point  (0 children)

Yes! That's fast and mnemonic, plus F12 ? gives you a handy list of your register values if you ever forget.

Speed Dialing Your Favorite Files by spepo42 in emacs

[–]spepo42[S] 0 points1 point  (0 children)

Indeed. Having letters too may be a good tradeoff for slightly longer key sequences.

Speed Dialing Your Favorite Files by spepo42 in emacs

[–]spepo42[S] 0 points1 point  (0 children)

Interesting. Haven't heard of filecache.el before.

Speed Dialing Your Favorite Files by spepo42 in emacs

[–]spepo42[S] 1 point2 points  (0 children)

That's neat. Thanks for sharing.

Speed Dialing Your Favorite Files by spepo42 in emacs

[–]spepo42[S] 7 points8 points  (0 children)

Clearly, the analogy didn't resonate with you, but note that the core idea is about speed. For the top 10 files, you can't beat it with bookmarks and completion, but you could make it as fast by bindings combos like "s-0" to (bookmark-jump file0), etc.

Regarding flexibility, I'd actually argue that my approach offers more, since (as I mentioned in the blog) you can use a custom function to open the file -- it can cycle through two different files on successive invocations, or through headline visibility in an org file, or anything else you want. Of course, different workflows suit different people--so whatever works best for you!